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
Related
I have phone numbers on my file and I would like to surround each of them with braces, so if I have this:
"+49-1111"
"+49-2222"
I would like to run a replace operation and to get this:
["+49-1111"]
["+49-2222"]
Is that possible with the current vs code find/replace action?
If it is a dup sorry but I could find any explanation anywhere.
Thanks
This is more relevant to regular expression.
Find ("\+\d{2}-\d{4}"), replace the occurrences with [$1]
Be sure to turn the "Use Regular Expression" switch on.
I need to write a regular expression to check the text Price:12-Jun-2017 where date can change.
I am working on SOAPUI at the moment and would like to add a JSONPath RegEx Assertion for checking this text.
Can someone help me?
Thanks
I am sure that ReadyAPI used in your case.
Select the right JsonPath Expression and Regular Expression as below value
Price:\\d{2}-[a-zA-Z]{3}-\\d{4}
I have a large LaTeX document where I have defined a macro like this:
\newcommand{\abs}[1]{\left|#1\right|}
I want to get rid of it by replacing in all the document \abs{...} by \left|...\right|, so I am thinking in a regular expression. I am familiar with their basics but I do not know how to find the bracket that closes the expression, given that the following situations are possible:
\abs{(2+x)^3}
\abs{\frac{2}{3}}
\abs{\frac{2}{\sin(2\abs{x})}}
What I have been able to do for the moment is \\abs\{([^\}]*)\} and then replace as \left\1\right|but it is only able to deal with the pieces of code of the first kind only.
By the way, I am using the TeXstudio regular expression engine.
Well, I did a little more of research and I managed to solve it. According to this response in a similar question, it suffices to use recursive regular expressions and a text editor that supports them, for example Sublime Text 2 (I could not do it with TeXstudio). This does the trick:
Find: \\abs\{(([^\{\}]|(?R))*)\}
Replace: \\left|\1\\right|
EDIT 1: Actually this solves only the two first cases, but fails with the third, so any idea on how to improve the regular expression would be appreciated.
EDIT 2: See comment from #CasimiretHippolyte for full answer using \\abs\{((?>[^{}]+|\{(?1)\})*)\}
I have a regular expression that looks for web site addresses in a piece of text. This is working fine unless there is a colon in the final part of the address.
It works for the following for example:
https://stackoverflow.com/questions/ask-a-question and the whole address is included.
However
https://stackoverflow.com/questions/ask:a-question
stops at the colon and "a-question" is not included.
The regular expression I am using just now is
((https?:\\/\\/([-\\w\\.]+)+(:\\d+)?(\\/([\\w/_\\-\\.\\?\\=\\%\\&]*(\\?\\s{1})?)?)?)?)(?<!\\.)
I also tried the following regex and it did the same as above.
(((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?))|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}
Any help would be brilliant, thanks.
try this
(\b(https?|ftp|file):\/\/)?[-A-Za-z0-9+&##\/%?=~_|!:,.;]+[-A-Za-z0-9+&##\/%=~_|]
http://www.phpliveregex.com/p/4Lt
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.