Actionscript regular expressions - regex

I have written the following regular expression:
[\s\S]*?,[\s\S]*?,(?P<lat>[\s\S]*?),(?P<long>[\s\S]*?)
In java it worked like a charm.
But when i use it in AS3 like this:
var pattern:RegExp = [\s\S]*?,[\s\S]*?,(?P<lat>[\s\S]*?),(?P<long>[\s\S]*?);
it gives an error...
I thought regular expressions where language independent...
Any help?
Thanks in advance.

I believe you need to add / delimiters to the front and back side of you regex.
What is an example string you are trying to use, and what is the desired output?
And what is the error you get?

Related

How to validate regular expresion working wrong

I'm writing a regular expression for a syntax highlight vscode extension and is not working as desired. The regular expression is in a plist file and is the following:
<string>(\#[\p{L}_]+[\w]*)</string>
I supposed that this expression will find #variable.
My problem is that is just finding the following: ##variable.
So it just find the string I want when it is preceded by an # character. Why is happening that?
When I write the expression:
<string>(\#[\p{L}_]+[\w]*)</string>
I supposed that this expression will find #key. That expression works correctly.
Furthermore, if I use this tool https://regexr.com/ to test regular expresions it is working fine. So what is the problem with vs code? It is something about the expresion flags maybe?
Anyone knows the problem?
The regular expresion is correct. The problem was that I was writing a vs code extension and I had to put this line in an upper position of the file because there was another regular expresion interfering.
Thank you! #WiktorStribiżew

regex change to detetct more pre-domain

I am new to regular expression and trying to learn changing the following regex, was wondering if you can help me.
The following will detect for me the links such as :
<http://www.ijs.si/software/delet.obo#VO_Broker>
regex:
<(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})
How do I change the same regex so it can also detect for me
<http://kt.ijs.si/software/delet.obo#VO_Broker>
I use the following regex to check for urls:
(\b(https?|ftp|file):\/\/[-\w+&##\/%?=~_|!:,.;]*[-\w+&##\/%=~_|])
Works fine and is a lot simpler.

Regular Expression for recognizing files with following patterns az.4.0.0.119.tgz

I am trying to find a regular expression that will recognize files with the pattern as az.4.0.0.119.tgz. I have tried the regular expression below:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
But, no luck. Can anyone please point me in the right direction.
Regards,
Shreyas
Better to use a simple regex like this:
^([a-z]+)\.(?:[0-9]+\.)+tgz$
You just forgot one number part:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
or
([a-z]+)[.]([0-9]{0,3}[.]){4}tgz
Depending on where and how you use the regex, you might want to surround it in ^...$.
Your pattern has 4 chiffers group, your regexp only 3.

Regular expression to pick extension

What would regular expression look like for any string which ends with .txt?
Tried few myself but it doesn't look like I'm getting anywhere.
I'd like to construct a regex object to feed a function.
Something like : .*\.txt$
If you want more precisions, I guess you should precise a language and some other stuffs...
All you have to do is match the end of the string using
/\.txt$/
Matching more than that e.g., .*\.txt$ is not necessary
Assuming Perl-style regular expressions, /[^\.]*\.txt$/ should work.

how to detect links in a string using RegEx in as3?

I am trying to find the generic links in strings. I've found a very handy regex on RegExr, in the community expressions:
(https?://)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?(:\d{1,5})?
I tried to use it and it returns null, although the same string tested on RegExr works fine:
var linkRegEx:RegExp = new RegExp("(https?://)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?(:\d{1,5})?","g");
var link:String = 'generic links: www.google.com http://www.google.com google.com';
trace(linkRegEx.exec(link));//traces null
Is there anything I'm missing ?
you need to double the backslashes when you're using new RegExp. you might want to use the literal syntax, which doesn't impose such a requirement (assuming AS3 admits this syntax, I just know JS.
Looks like maybe you're trying to match the wrong variable? In line linkRegEx.exec(formattedStatus), formattedStatus isn't defined.