This question already has answers here:
Regex to get all character to the right of first space?
(4 answers)
Closed 3 years ago.
I'm trying to get this via regex. I have a series of strings that all have the same general structure:
10-1:15 Build Support: (available)
A number, a space, a string following, a colon, and a string.
I need to extract the string portion after the first white space
Build Support: (available)
How can I regex this?
Side note: I'm on a Ruby project so I've been beating my head on https://rubular.com/.
This is something quick I came up on rubular:
https://rubular.com/r/tlfeSPy7zhfRN7
I tried matching with a group of non word characters and then capturing subsequent word characters. Match 2 should be what you're looking for.
Related
This question already has answers here:
Searching for all variations of hyphens and dashes in Regex
(2 answers)
Closed 6 months ago.
Hyphen, figure dash, en dash, em dash, horizontal bar and hyphen-minus: I want to have a regex expression to detect any one of these separators (character representing an horizontal central line).
Till now I got this:
/[\-\–\—\−\―]/
but I don't know if it is robust enough and btw, I wanted to have with the character codes, to avoid changing the character upon some copy-paste conversion.
Finally found:
[\u002D\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\u2E3A\u2E3B\uFE58\uFE63\uFF0D]
Got the codes from here, but I just used, as stated in the question, the single horizontal lines
This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 3 years ago.
Link Regex101
I am using (FD.*?)FD however I am missing every second expression - see regex. Any ideas?
The trailing "FD" in your regex matches the "FD" in the input that starts the next "item" in the input text, so the entire next "item" is skipped, until it finds another "FD".
In a case like this, instead of specify .* followed by the pattern that starts the next item, you typically want to specify anything not including a pattern of FD.
This question already has answers here:
How to negate specific word in regex? [duplicate]
(12 answers)
Closed 3 years ago.
I'm trying to scan all attributes from a database, searching for specific patterns and ignoring similar ones that I know should not match but I'm having some problems as in the below example:
Let's say I'm trying to find Customer Registration Numbers and one of my patterns is this:
.*CRN.*
Then I'm ignoring everything that are not CRNs (like currency and country name) like this:
(CRN)(?!CY|AME)
So far everything is working fine as look ahead is included in Javascript
The next step is to exclude things like SCRN (screen) for example but look behind (?<!S)(CRN)(?!CY|AME) doesn't work.
Is there any alternative?
Example inputs:
CREDIT_CARD
DISCARD
CARDINALITY
CARDNO
My Regex (?!.*DISCARD.*|.*CARDINALITY.*).*CARD.*
CARDINALITY was removed but DISCARD still being considered :(
The regex that you want is:
(?!\b(?:CARDINALITY|DISCARD)\b)(\b\w*CARD\w*\b)
It is important that you are testing the negative lookahead against the entire word and thus we are trying to match (\b\w*CARD\w*\b) rather than just CARD. The problem with the following regex:
(?!(?:CARDINALITY|DISCARD))CARD
is that with the case of DISCARD, when the scan is at the character position where CARD begins, we are past DIS and you would need a negative lookbehind condition to eliminate DISCARD from consideration. But when we are trying to match the complete word as we are in the regex I propose, we are still at the start of the word when we are applying the negative lookahead conditions.
Regex Demo (click on "RUN TESTS")
This question already has answers here:
regex for string starts with X and contains Y
(2 answers)
Closed 4 years ago.
I am trying to check whether a string starts from a particular word And also a particular substring occurs in it.
So lets say if I have a string like this:
SCSI\DISK&VEN_MICRON&PROD_1100\4&2096297&0&000200
I need to check whether this string has 4&2096297&0 and also it starts from SCSI
I did this : (^SCSI|\\4&2096297&0) . This is pretty much doing the work but it is also selecting the substring even if the string doesn't start from SCSI
Regex101 : Attempt
It is working as expected but the problem is it is selecting a substring even if the string doesn't start from SCSI.
Is it possible to put a AND condition to it.
You don't want to alternate with | - that will fulfill the regex if the left side or the right side of the | matches. You want to check that both conditions match. After the beginning of the string and SCSI, try repeating characters until you get to 4&2096297&0:
^SCSI.*4&2096297&0
https://regex101.com/r/xV0tHI/4
If you want to capture the already-hard-coded SCSI and 4&2096297&0, then put parentheses around them:
^(SCSI).*(4&2096297&0)
This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 4 years ago.
I am trying to find all strings not ending with the sequence -6X.
What i'm trying to do is compare the value of an xml tag with a sequence.
If it matches then do some stuff.
However I am unable to do so. I want to achieve this without any lookaheads or lookbehinds.
I've tried using .*[^-6X]
However this does not work for strings ending in - or -5 .
I want to ignore strings ending in -6X only and every other pattern should work.
Thanks in advance for your help
This matches Strings NOT ending with -6X:
.*?([^-]..|.[^6].|..[^X])$
https://regex101.com/r/omwkQ3/2