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.
Related
I am trying to find any word which ends 'k' letter and must be come after these letters 'a,e,o'.
Regex should find this:
'stack'
'kick'
'kiik'
'kimk'
'gesk'
and should not find belows:
'book'
'beak'
'aiok'
For this gain i use this reguler expression :
(?![aeo]+k)^.*?$
. But it does not work.
^.*(?<![aeo])k$
You can use this as all your words are ending with k.See demo.The lookbehind will separate out the words having aeo just before the last k.
https://regex101.com/r/cD5jK1/3
You can use this negation based regex:
^.*[^aeo]k$
RegEx Demo
You may not have provided enough information, but I don't see why any sort of lookaround is warranted here. You should be able to simply use:
\b[A-Za-z]*[aeo]k\b
Word boundaries ( \b ) will help you limit this pattern to only words. If you need to account for hyphens, then you could adjust the first range to include hyphen as well.
I am scratching my head over this. For example I have:
Date
sometext
somtext
27-7-2013
What I want to do is I want to get the first date format string pattern after the Date keyword. Here is what I currently have:
(?i)(?<=date.*)\d+-\d+\d+
But unfortunately, I am getting nothing and if I just try to get all the string after the date keyword, e.g.
(?i)date.*
I am only getting the result as:
Date[CR]
I am using Expresso to test out my regular expressions. I am pretty new with using regex so I am not familiar with how to do things and stuff.
Please help! Thanks!
I would not use a lookbehind assertion in this case, also unlimited length lookbehinds are (I think) only supported by .net.
I would use a capturing group instead:
(?is)date.*?(\d{1,2}-\d{1,2}-\d{4})
You will find the date in the first capturing group.
See it here on Regexr
(?is) is enabling the case independent matching mode i and the single line mode s, that makes the . also match newline characters.
.*? is matching lazily any characters.
(\d{1,2}-\d{1,2}-\d{4}) matches one or two digits, a dash, one or two digits, a dash, then 4 digits.
You can have a look at this regex:
(?i)(?<=Date)[\S\s]*?(\d{1,2}-\d{1,2}-(?:\d{4}|\d{2}))
In your regex you are also missing a - before last \d+. Also this regex will handle the year part with four digits as well as two digits.
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]*$
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]+)$
I need some help with regex.
I have a pattern AB.* , this pattern should match for strings
like AB.CD AB.CDX (AB.whatever).and
so on..But it should NOT match
strings like AB,AB.CD.CD ,AB.CD.
AB.CD.CD that is ,if it encounters a
second dot in the string. whats the
regex for this?
I have a pattern AB.** , this pattern should match strings like
AB,AB.CD.CD, AB.CD. AB.CD.CD but NOT
strings like AB.CD ,AB.CDX,
AB.whatever Whats the regex for
this?
Thanks a lot.
Looks like you've got globs not regular expressions. Dot matches any char, and * makes the previous element match any 0+ times.
1) AB\.[^.]*
Escape the first dot so it matches a literal dot, and then match any character other than a dot, any number of times.
2) "^(AB)|(AB\.[^.]*\.[^.]*$"
This matches AB or AB followed by .<stuff>.<stuff>
http://www.regular-expressions.info/ contains lots of useful information for learning about regular expressions.
If your regex engine supports negative lookahead you might try something like:
^AB\.[^.]+$
^AB(?!\.[^.]+$)
(or
^AB\.[^.]*$
^AB(?!\.[^.]*$)
if you want to allow AB. )
I don't find you're question entirely clear; please comment here (or edit your question if you can't add comments) if I'm getting this wrong but what I think you're looking for is:
1) matching strings "AB.AnyTextHereWithoutDots" but not "AB" or "AB.foo." etc
If so a matching regex would be:
"^AB\.[^.]*$"
2) matching "AB" or "AB.something.something" with either none or two or more dots
If so a matching regex would be something like:
"^AB(\..*\..*)?$" or "'^AB\(\..*\..*\)\?" (depending on the nature of your regex engine)
As Douglas suggests matching with globs would likely be easier.
And as spdenne suggests, find a good regex reference.
I tried this in vim. Here is the sample data:
AB.CD
AB.CDX
AB.whatever
AB
AB.CD.CD
AB.CD.
AB.CD.CD
Here is my regexes
This captures all lines starting with AB and then expects a literal dot, and then filters out all lines that has a second dot.
^AB\.[^.]*$
This captures all lines that is just an AB (the part before the pipe) or lines that start with AB that is followed by two literal dots (escaped with a backslash)
^AB$\|^AB\..\..$