I want to match everything between "02A1" and "03" IF its 14 characters in between those two.
My RegEx Pattern looks like this:
(02A1)[0-9A-Z]{14}(03)
My problem: It also matches this:
02A103EEFFFFF702A103
What am i doing wrong? "EEFFFFF7" is clearly not between 02A1 und 03 as before the EEFFFFF7 theres a 03 and after it theres a 02A1.
Can someone help me?
If the fourteen alphanumeric chars cannot contain a 03 substring, use
02A1(?:(?!03)[0-9A-Z]){14}03
If it cannot contain 02A1 either, use
02A1(?:(?!03|02A1)[0-9A-Z]){14}03
See this regex demo.
Details:
02A1 - a 02A1 string
(?:(?!03|02A1)[0-9A-Z]){14} - fourteen occurrences of an uppercase ASCII letter or digit that does not start a 03 or 02A1 char sequence
03 - a 03 string.
Related
I want to remove everything including digits, characters, special characters from a file except 01 - 10 pattern. For example:
01 - 10
This is the first one :1
02 - 20
This is the second one -2
03 - 30
This is the third one "3
04 - 40
This is the forth one ;4
05 - 50
This is the fifth one .5
The regex that I have used is [^\d\d\s-\s\d\d], keeping in mind to match everything except "01 - 10" pattern by selecting \d\d\s-\d\d and using character set charet(^).
But using this I'm getting:
01 - 10
1
02 - 20
-2
03 - 30
3
04 - 40
4
05 - 50
5
But I want the result to be:
01 - 10
02 - 20
03 - 30
04 - 40
05 - 50
I.E., I want, 01 - 10 pattern and, not to include any individual :1 and -2 and "3 and ;4 and .5 as mentioned in the problem at the top.
And vice versa i.e. to select each line except the "01 - 10" pattern
eg:
This is the first one :1
This is the second one -2
This is the third one "3
This is the forth one ;4
This is the fifth one .5
I want to know the regex pattern for 01 - 10 case and vice versa so that I can keep both the separately generated results in separate files.
You may use this regex:
^(?!\d{2}\h*[:-]\h*\d{2}\h*$).*[\r\n]
RegEx Demo
RegEx Details:
^: Start
(?!: Start negative lookahead
\d{2}: Match 2 digits
\h*[:-]\h*: Match 0 or more horizontal whitespaces followed by : or - followed by 0 or more horizontal whitespaces
\d{2}: Match 2 digits
\h*: Match 0 or more whitespaces
$: End of the line
): End negative lookahead
.*: Match anything
[\r\n]: Match 1+ of line breaks
Replacement is an empty string to remove all matching lines
Reverse Removal
To remove digit pair lines you can use:
^(?=\d{2}\h*[:-]\h*\d{2}\h*$).*[\r\n]+
RegEx Demo 2
Use this:
^(?!\d\d\s-\s\d\d).*
Demo: https://regex101.com/r/t4qrh0/1
I need to match and replace all UPPERCASE word in a Postgres string field like
'GARLASCO Cavour/Oriani'
'SANNAZZARO DE' BURGONDI Italia, 46 (Direzione Sud)'
'S.MARGHERITA STAFFORA Vallechiara (Bivio Montemartino)'
'GAMBOLO' Umberto I, 312'
I try with
[A-Z\''.]{2,}
SELECT REGEXP_REPLACE('SANNAZZARO DE' BURGONDI Italia, 46 (Direzione Sud)',' \b[A-Z]{2,}\b','','g')
but it works only for string with 1 uppercase world like 'GARLASCO Cavour/Oriani'
You may use
REGEXP_REPLACE(your_col_here,' '^[A-Z[:space:].'']+\y','')
This will replace the following matches:
^ - start of string
[A-Z[:space:].']+ - 1+ uppercase letters (you may also replace A-Z with [:upper:]), whitespaces, dots or apostrophes at...
\y - a word boundary.
Trying to extract the numbers from a string of pattern:
<Some Alphanumeric> <numbers> X <numbers> <Some Alphanumeric>
e.g.
I 00 Crazy 060 X 0140 08 Dance 47
should extract the numbers 060 and 0140 and the text I 00 Crazy and 08 Dance 47
I'm using the following Regex:
(.*)(\d{1,3})\s*(x|X)\s*(\d{1,4})(.*)
However this isn't working on the first number preceding the X, it's only capturing 0 instead of 060 but captures the second number 0140 correctly.
\d{1,3} should be a greedy capture of digits between 1 and 3 in length - so what am I missing here?
This should work,
(.*)\b(\d{1,3})\s*(x|X)\s*(\d{1,4})(.*)
Here, \b asserts position at a word boundary (^\w|\w$|\W\w|\w\W)
I want a Regex for version that accepts this format:
##.##.##
====
but that doesn't accept
00.00.00
If your regex dialect supports negative lookahead assertions (?!...) this is easy:
^(?!00\.00\.00$)(\d{2}\.){2}\d{2}$
If your regex dialect does not support ?! and/or \d, please update your question with pertinent details and/or tags.
If only 00.00.00 is not acceptable, then you can use the following regex
00\.00\.(?:0[1-9]|[1-9]\d)|00\.(?:0[1-9]|[1-9]\d)\.\d{2}|(?:0[1-9]|[1-9]\d)\.\d{2}\.\d{2}
A regular expression could look like this:
(0[1-9]|[1-9]\d)\.(0[1-9]|[1-9]\d)\.(0[1-9]|[1-9]\d)
(\d is a digit, \. is a dot, [1-9] is a digit from 1 to 9)
explanation in detail:
0[1-9] will match numbers from 01 to 09
[1-9]\d will match 10 to 99
(0[1-9]|[1-9\d) will match either 01 to 09 or 10 to 99 (so any number from 01 to 99)
these will be accepted:
01.01.01
11.11.11
55.55.55
55.01.33
10.20.30
these will not be a match:
00.01.01
00.00.00
44.33.00
http://regex101.com/r/lE7uH6
I'm trying to use regular expression in Notepad++ to change spaces to tabs in something like this
01 fsdfsd
01 01 fsdfsd
01 01* fsdfsd
01 01 01 fsdfsd
01 01 01* fsdfsd
How can I keep spaces between numbers and change only the last space?
Thanks.
Search for:
[ ]([a-zA-Z])
(Note that there is a space in front of the character class.) And replace with:
\t$1
An alternative that might be better suited if you also have lines that are of a different format, or if fsdfsd may contain spaces, is this:
^((?:\d+\*?)(?:[ ]\d+\*?)*)[ ]
Now replace with
$1\t
This matches any space after the longest possible string of digits with optional asterisks separated by spaces.
You could use a look head to only match on space followed by something other than a digit, but because notepad doesn't support look arounds, you must resort to a capture-and-release approach looking for a letter:
search: " +([a-zA-Z])" (don't include the quotes - there to show the space)
replace: \t$1