Can someone tell me the regular expression for this? - regex

I am working with regular expressions, I need to create an expression for validating strings against the following scenario:
Solution.<word1|word2|word3>.<word4|word5>.anyword.(any word containing proj in it)
I tried
Solution.\b(word1|word2|word3)\b.\b(word4|word5)\b.(.*).\b(.*proj)\b
But this allows strings like Solution.word1.word4.blabla.blabla.csproj, meaning it allows anything before the proj because of the .*.
Can someone help me with this??

Looks like you need this regex:
Solution\.(word1|word2|word3)\.(word4|word5)\.([^.]+)\..*?\bproj\b
RegEx Demo

You might want to try (need to escape the . and allow capturing group to have chars except .):
Solution\.\b(word1|word2|word3)\b\.\b(word4|word5)\b\.([^\.]*)\.\b([^\.]*proj)\b

It's hard to consider the actual strings you want to allow without more clarification.
You can try the following regular expression.
Solution\.word[123]\.word[45]\.\w+\.\w*proj\b

Related

Nino Regular Expression

I have the following text, for example:
nino&searchPhrase=jn123456&alphabetical
And I want to extract jn123456.
I've put together the following regex to extract NINOs:
(\bnino?\b.*?|Nino?\b.*?)[a-zA-Z]{2}[0-9]{6}
The problem I have is at the very end of the regex where I'm matching the last alpha character which may or may not be there.
I've tried adding the following at the end of the regex shown above without any luck:
?[a-zA-Z]{1} and
[?a-zA-Z]{1}
Could someone please look at this and let me know where I've gone wrong.
Many thanks and kind regards
Chris
You may use something like this:
^[Nn]ino&?\w*=([a-z]{2}\d{6})
which will capture "jn123456" in the first capturing group.
Demo.
If the character & can be anything else, then you may use . instead.

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 Expressions with conditions

I have a string that looks like:
this is a string [[and]] it is [[awesome|amazing]]
I have the following regular expression so far:
(?<mygroup>(?<=\[\[).+?(?=\]\]))
I am basically trying to capture everything inside the brackets. However, I need to add another condition that says: If the matched result contains a pipe delimiter then only return the word to the right of the pipe delimiter. If there is no pipe then just return everything inside the brackets.
The parsing result I am looking for given the example above should look like:
and
amazing
Any input is appreciated.
(?<mygroup>(?<=\[\[)([^|\]]*|)?([^|]+?)(?=\]\]))
You could use this regex:
(?<=\[\[[^\]]*?)(?!\w+\|)\w+(?=\]\])
it matches both and and amazing words in your test example. You could check it out, I created a test app on Ideone.
From the regex info page:
The tremendous power and expressivity
of modern regular expressions can
seduce the gullible — or the foolhardy
— into trying to use regexes on every
string‐related task they come across.
My advice: Just grab what is between the brackets and parse it after.
Regular expressions are not the answer to everything. May those who follow after you be spared from deciphering the regex you come up with.

Regular Expression with specific criteria

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$

matching table tag by regular expression in php

I need to match a substring in php substring is like
<table class="tdicerik" id="dgVeriler"
I wrote a regular expression to it like <table\s*\sid=\"dgVeriler\" but it didnot work where is my problem ?
You forgot a dot:
<table\s.*\sid="dgVeriler"
would have worked.
<table\s+.*?\s+id="dgVeriler"
would have been better (making the repetition lazy, matching as little as possible).
<table\s+[^>]*?\s+id="dgVeriler"
would have been better still (making sure that we don't accidentally match outside of the <table>tag).
And not trying to parse HTML with regular expressions, using a parser instead, would probably have been best.
I dont know what you want get but try this:
<table\s*.*id=\"dgVeriler\"