Since i'm not so good at regex how can i match some conditions in a string, StaticString_1number:1number:more than 1number.
Example:
string_3:0:12344555 - Match
string_s:0:12344555 - No match
string_3:s:12344555 - No match
string_3:0:123s4555 - No match
Thanks.
This Regex would solve your problem:
^[a-zA-Z]+_[\d]{1}:[\d]{1}:[\d]+$
You can check this link for verification: http://regexr.com?34uj5
If I understand your pattern StaticString_1number:1number:more than 1number correctly your regex to match against such strings could look like the following:
'^[a-zA-Z]+_[0-9]:[0-9]:[0-9]+$'
or if your environment support character classes:
'^\w+_\d:\d:\d+$'
This should suit your needs:
^[^_]+_\d:\d:\d+$
Demo
If the initial String can only have characters a-z then the following should work :
[a-z A-Z]+_\d:\d:\d+
this will match any number of letters up to an underscore then look for single digit before and after colon and multiple digits after second colon.
but you should really have an attempt your self. if in python you could try re-try or in javascript regexpal and try out your regex patterns there first.
This may help : ^[a-zA-Z]*_[0-9]:[0-9]:[0-9]*$
Related
I'm trying to filter words which is not in the "[ ]".
Why is this not working?
[^\[][\u0000-\u024F]+[^\]]
The reason your expression is not working is that it matches all text inside brackets as well as outside.
This is the best I've been able to do:
/(?:^|])[^[]+/g
It includes the ]s in the match because look-behind is not allowed:
http://regexr.com/3c515
If look-behind were allowed, this would be the ticket:
/(?:^|(?<=]))[^[]+/g
https://regex101.com/r/lK9tS7/3
Because this will match [\u0000-\u024F]+ and 2 character which will be matches by [^\[]. If you want to your regex engine match the whole of pattern you need to use start and end anchors in your regex :
/^[^\[][\u0000-\u024F]+[^\]]$/m
But this will work if your string is contain words in each line, which is not a proper way.
As a better way you can use negative look arounds :
(?<!\[)[\u0000-\u024F]+(?!\])
I would like to build [A-Za-z] regex but with zero to one [\'] apostrophe inside that string.
Thanks.
^([a-zA-Z]+)?([[a-zA-Z]+\']{0,1})?[a-zA-Z]+$
Please find regex for alpha with apostrophe optionally.
Valid test case:
D'souza
Peter
Nil's
Invalid test case:
'Tom
Mark'Two'
Something like: [A-Za-z]*'?[A-Za-z]* seems like it would work--an arbitrary number of letters followed by an optional apostrophe, followed by an arbitrary number of more letters.
/^[A-Za-z]*'?[A-Za-z]*$/
Depending on your regular expression flavor, that should work.
I need a regexp that I want to match against several different strings.
The regex should retrieve a match for this string:
http://www.domain.com/category
But not for this:
http://www.domain.com/category/sports
or
http://www.domain.com/category/sportsmanship
I have tried the following regex but it doesn't really want to work:
/categ.*?^((?!sports).)*$/g
You can use this regex:
.*/category(?!/sports).*
Working demo
You can write
/\/categ[^\/]*(?:\/(?!sports)[^\/]*)*$/
In this pattern, the negative lookahead checks after each slashes if the string "sports" doesn't follow.
Note: if you have to deal with long paths that contains the string "sports" relativly often, you can try this variant to speed up the pattern:
/\/categ(?=([^\/]*))\1(?:\/(?!sports)(?=([^\/]*))\2)*$/
I think you don't want to match the line which contains the string sports at the last. If yes then you could try the below regex,
^.*?categ(?:(?!sports).)*$
The problem with your regex is .*?^. ^ asserts that we are at the start of a line.
I am on a quick project cannot learn regex at the moment so need some help. I know its too basic. Please tell me regex that matches expression containing a "becoming_*" but not those containing period. For example
Matchs following expressions:
becoming_1
becoming_2
becoming_20
But does not match
becoming_1.1
becoming_1.5
becoming_2.1
becoming_20.1
becoming_20.50
You could try the below regex to match the lines which has the string becoming_ followed by an integer number,
^becoming_\d+$
OR
^becoming_[0-9]+$
DEMO
You want a string that ends with numbers and not including a period - that's why we are using \d+ - for numbers, and $ - that nothing should be after that.
/becoming_\d+$/
Try a negative lookahead with a boundary
(becoming_\d+\b(?!\.))
You did not tag the question with a specific language, so I am not sure which dialect you are using.
I search for a regex pattern, which shouldn't match a group but everything else.
Following regex pattern works basicly:
index\.php\?page=(?:.*)&tagID=([0-9]+)$
But the .* should not match TaggedObjects.
Thanks for any advices.
(?:.*) is unnecessary - you're not grouping anything, so .* means exactly the same. But that's not the answer to your question.
To match any string that does not contain another predefined string (say TaggedObjects), use
(?:(?!TaggedObjects).)*
In your example,
index\.php\?page=(?:(?!TaggedObjects).)*&tagID=([0-9]+)$
will match
index.php?page=blahblah&tagID=1234
and will not match
index.php?page=blahTaggedObjectsblah&tagID=1234
If you do want to allow that match and only exclude the exact string TaggedObjects, then use
index\.php\?page=(?!TaggedObjects&tagID=([0-9]+)$).*&tagID=([0-9]+)$
Try this. I think you mean you want to fail the match if the string contains an occurence of 'TaggedObjects'
index\.php\?page=(?!.*TaggedObjects).*&tagID=([0-9]+)$