Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Using RegEx, I am trying to match any e-mail address outside of a code comment.
For example, the string could be something like this:
/**
* Hello World
* For comment info e-mail us at test#email.com
*/
But we really want to match this#email.com
So in this case, I would only want to return 'this#email.com'. What RegEx formula could I use in this case?
Regular expressions are often seen as some magic language that will do anything we need with a text string if only we knew the incantation. It's not like that, and you shouldn't let your progammer-sense be subverted by the idea. Your core language should do the heavy lifting, leaving regex patterns to do the detailed work
It's unclear whether you need a Perl solution or a JavaScript one, or if you're equivocal. This is for Perl
How to "match any e-mail address outside of a code comment"?
Remove the comments
This is addressed in perlfaq6
Search for email addresses
You should use the
Regexp::Common module, together with
Regexp::Common::Email::Address.
But beware that this will match anything defined by the Internet Message Format standard, which may be rather more than you imagine an "email address" to be. It's a lot more than just bob#example.com
See also
Email::Address
if you need to process any email addresses that you find
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am attempting to make a Discord bot that will post the top tweet of a hashtag when requested however I cannot figure out how to do this. I cant find anything for searching tweets of a hashtag in the Twitter API. How can I achieve this? Alternate solutions are welcome but I need it to be a Discord bot. Thanks!
Did you look at the search API documentation? There's an example for a hashtag right there:
Standalone operators can be used alone or together with any other
operators (including those that require conjunction).
For example, the following query will work because it uses the
#hashtag operator, which is standalone:
#twitterapiv2
You will need to do some work in your code to decide what constitutes "the top tweet" - do you mean the most recent Tweet, the Tweet with most likes, the most retweets, etc - you will have to check the metrics on the Tweet objects to decide which Tweet is "top" in your definition, there's nothing built-in to the API that returns just the "top" Tweet, unless you just want the most recent result.
Judging by the this api reference they have a custom query thing going on. I'm sure you should be able to use their query options to get the data you want
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a problem that on specific view request.user returns AnonymousUser.
This is caused by a javascript library which I use to collect payments. That javascript library makes a cookie which makes django see a logged-in user as AnonymousUser.
If I delete that cookie, django sees the user as logged-in but after a couple of refreshes, I get a new cookie which makes again the logged-in user an AnonymousUser.
And I have this issue only in one specific page where that library is inserted in the page.
Any ideas what is wrong?
The javascript in question sets a cookie by the name mistertango[collect][mt_fp].
When cookies was defined (RFC 6265, I guess) it seems they didn't really specify what characters you're allowed to use in a cookie name, other than basically «text».
This causes some problems with parsing cookie names. Django relies on Python's http.cookies for this, and it seems http.cookies doesn't allow brackets in cookie names. http.cookie failes to parse cookie pairs with brackets in it, and doesn't parse pairs after that which means it doesn't see the sessionid cookie it uses for authentication.
I'm not able to tell if Django/http.cookie should or shouldn't support this.
PHP does however seem to support it (even if it's broken), while Ruby on Rails does not.
The easy solution is to use only alphanumeric characters in cookie names.
For your case, the best solution is to get the javascript author to change their cookie name. If that's not possible, or in the mean time, you could host the javascript yourself and change the cookie name in your copy. (This may not work if the cookie is used for something outside of this javascript snippet, but I don't really understand Javascript and does not see what it is used for.)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a rest call that sends addresses to the back-end. When an address contains a / e.g. c/o (corner of) I get a 400(bad request... i've tried to encodeURIComponent(query) but even though the address is encoded it still gives me the same error. i'm planning on replacing each occurance of / with $ in the rest call and then replacing the $ with a / again on the back-end. Is this the only way to go about this or is there a propper way of doing this?
The forward slash or / is a special char in URI encodings, it is used to separate arguments for the path to the file we want to access. So it obviously can not be used as we please. The encodeURIComponent function from Jquery will encode this character but it will be interpreted by your server as a keyword in most cases.
Your solutions are:
Either send using POST, which is the cleanest way to send text without having to care about its encoding.
Or replace the / with its html enity code which is: /, that way, you can send it via GET and it will still be understood by HTML as a / but no longer as a special character.
Hope it helps
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to develop products filters for an online store I am working on. An example of what I mean is http://www.riverisland.com/men/just-arrived. I have managed to get a JavaScript to populate the URL when the sizes are clicked on but failed to get them remove value from URL when unchecked.
My main question here is this. Assuming I have my URL as:
http://127.0.0.1/shop/dresses/?s=1&s=2&s=3
How do I get my PHP to extract the values from the URL?
How do I format a SQL query to search the values gotten from the URL using any sample query?
An easier solution is this.
Format your URL like http://127.0.0.1/shop/dresses/?s=1,2,3 as suggested by #Andrey.Popov. Then do the below.
if(isset($_GET['s']) && !empty($_GET['s']))
{
$e = sanitizeFunction($_GET['s']);
$d=explode(',',$e);
}
$d now has all your $_GET['s'] values.
That's the easier way I have figured out and it works!
In order to benefit from $_GET and other superglobals you have to follow the rules explained at Variables From External Sources. Since you've chosen to have several parameters with the same name and they do not contain properly paired square brackets you're basically on your own. The manual steps you must reproduce include:
Extract the raw query string from $_SERVER['QUERY_STRING'], e.g.:
$query_string = filter_input(INPUT_SERVER, 'QUERY_STRING');
Parse out the string. As far as I know, there aren't built-in functions that do exactly this so I'd either google for a good third-party library or write a simple parser with regular expressions or good old explode().
Decode the URL-encoded values with urldecode()
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Trying to combine two regexes from here to validate host names and IP addresses in a single statement.
I've got them working separately, but when combining using |, things get screwy, matching fragments of host names and ips, not whole valid patterns, which is not what I want. I need a single regex, using the host name and IP patterns below, to match either host or IP addresses.
I've provided scratch pads where I've tested each pattern; the last one is my attempt at combining them, with examples illustrating regex matching invalid fragments.
regex: Host Names
^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))$
regex: IP Address
^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})$
regex: Host name and IPs (not working)
^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})$
You had a precedence issue. When you wrote
^(regex1)|(regex2)$
It was interpreted as
(^(regex1))|((regex2)$)
So any line starting with a valid hostname or ending in an IP address matched ok. A solution is to do
^regex1$|^regex2$
Which comes out as:
^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})$|^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))$