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]+)$
Related
I am trying to select part of a URL /example/privacy-policy and /example/123/privacy-policy but not /privacy-policy
I currently have this ^[^\/privacy\-policy].\/privacy\-policy.$
But it seems to not work still. Ideally, it would be able to find privacy-policy anywhere in the string without directly matching the root /privacy-policy
Thank you very much!
^.*(?=\/privacy-policy)
This matches everything (.*) from the beginning of the string (^) up until the string /privacy-policy appears. (This is called a positive lookahead)
If you only want to match privacy-policy at the end of the string, but not
when is it /privacy-policy at the start of the string and using a lookbehind assertion is supported:
(?<!^\/)\bprivacy-policy$
Explanation
(?<!^\/) Negative lookbehind, assert not the start of the string followed by / directly to the left
\bprivacy-policy Match literally preceded by a word boundary to prevent a partial match
$ End of string
See a regex demo.
If you don't want privacy-policy as the root of your url, but you still want to match it, you can force the regex to look for at least one more symbol before the backslash that preceeds privacy-policy:
(.+\/)privacy-policy
Then if you want to get the part that comes before privacy-policy, you can reference Group 1.
Is this what you're looking for?
I am trying to create a regex expression to parse till \. Can you tell me how to create a regex expression.
The code i had created was
/[^\]*/
I find regex101.com really useful for testing regex.
I think you just need an extra backslash...
/[^\\]*/
If you want to get everything until a slash, just use:
/(.*?)\\/
(.*?) Capture group, containing the text until slash (not included)
.* Match everything 0 or more times.
? make the quantifier (*) lazy, so it matches only until the first slash if there are more than one.
Check this: http://regexr.com/3cnld
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 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.
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]*$