Please find expression for example string :
john/niel
Stephanie/Arnold
I wrote:
^[a-zA-Z/][a-zA-z]+$
But it accepts multiple slash also.
This is really basic. If you Googled for a minute or two, I'm sure you'd come up with something like
^[a-zA-Z]+\/[a-zA-Z]+$
The quoting of the / might not be necessary - depends on regex flavor.
Regards
Related
I'm upgrading a Symfony app with VSCode and I have numerous occurences of this kind of string :
#Template("Area:Local:delete.html.twig")
or
#Template("Group:add.html.twig")
In this case, I want to replace all the : with / to have :
#Template("Area/Local/delete.html.twig")
I can't think of doing it manually, so I was looking for a regular expression for a search/replace in the editor.
I've been toying with this fearsome beast without luck (i'm really dumb in regexp) :
#Template\("([:]*)"
#Template\("(.*?)"
#Template\("[a-zA-Z.-]{0,}[:]")
Still, I think there should be a "simple" regexp for this kind of standard replacement.
Anyone has any clue ? Thank you for any hint
You can use this regex with a capture group: (#Template.*):.
And replace with this $1/.
But you'll have to use replace all until there's no : left, that won't take long.
Just explaining a lit bit more, everything between the parenthesis is a capture group that we can reference later in replace field, if we had (tem)(pla)te, $1 would be tem and $2 would be pla
Regex!
You can use this regex #Template\("(.[^\(\:]*)?(?:\:)(.[^\(\:]*)?(?:\:)?(.[^\(\:]*)?"\) and replacement would simply be #Template\("$1/$2/$3
You can test it out at https://regex101.com/r/VfZHFa/2
Explanation: The linked site will give a better explanation than I can write here, and has test cases you can use.
I am trying to develop a regular expression to extract this: PT~MM:SS~EQP>G-G<EQP from a file.
PT is optional but if it is present it's only valid if it is 1P, 2P, 1EP or 2EP.
So if the example is: 3EP~101:37~POR>4-2<ISL it shouldn't be matching nothing but I am getting 2EP~101:37~POR>4-2<ISL as a match.
So far I've tried this:
(((1|2)P|(1|2)EP)~)?(0{0,1}([0-9]|[1-8][0-9]|9[0-9]|1[01][0-9]|120)):(0*([0-9]|[1-4][0-9]|5[0-9]))~[A-Z]{3}>[0-9]-[0-9]<[A-Z]{3}
Can someone help me?
This might what you are looking for ^(?:[12]E?P)?~?\w+?:\w+?~\w+?>\w-\w<\w{3} (https://regex101.com/r/T8Cy4C/6). Although you did not specified fully what are the requirements for each parts.
I am trying to write a regex in C++ that would match any of the following statements:
0=250
26000=0.86M
0=250|18000=300
0=250|18000=300|26000=0.86M
I wrote the following and checked with regexr.com:
(([0-9]+=[0-9]+)|((\|[0-9]+=[0-9]|.[0-9]+)[Mm]))((\|[0-9]+=[0-9]+)|((\|[0-9]+=[0-9]|.[0-9]+)[Mm])?)+
It looks like it is working, but I do not understand one thing. I thought I needed double backslashes before ".", like:
(([0-9]+=[0-9]+)|((\|[0-9]+=[0-9]\\.[0-9]+)[Mm]))((\|[0-9]+=[0-9]+)|((\|[0-9]+=[0-9]\\.[0-9]+)[Mm])?)+
as I was advised in my other post. However, according to the online tester, this is not correct.
Can someone explain please?
Thanks a lot!
This depends on the flavor of regex that you are using. Regex doesn't have universal rules, and some of the main differences are what characters need to be escaped when.
I don't know what flavor your online tester was, but here is what c++ 11 uses for regex: http://www.cplusplus.com/reference/regex/ECMAScript/
You will need to escape all literal . and | characters in your regex according to this.
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.
Hey everyone, I'm trying to type a regular expression that follows the following format:
someone#somewhere.com or some.one#some.where.com
There are no special characters or numbers permitted for this criteria. I thought I had it down, but I'm a bit rusty with regular expressions and when I tested mine, it failed all across the boards. So far, my regular is expression is:
^[a-zA-Z]+/.?[a-zA-Z]*#[a-zA-Z]+/.?[a-zA-Z]*/.com$
If anyone could help me, it would greatly be appreciated, thanks.
your regex looks good. I think you need to change the / to \ in front of the . .
Additionally, if you don't want someone.#somewhere..com pass your regex, u should change your regex to
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$
(not completely sure about the brackets () though, but i think that should be working)
its a backslash to espace dots. Also put the the parenthesis around the . and what follows otherwise an email like abc.#cde..com would be valid.
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$
It looks mostly OK. Change your / to \ though...
For the second case, I would ensure that if you have a . in the middle, it must be followed by more letters:
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$