Postgres regular expression - get everything before second space [duplicate] - regex

This question already has answers here:
pcre regex to match first two words, numbers
(3 answers)
Closed 22 days ago.
I've got query
select(REGEXP_MATCHES('isu_lib.directions_directions_isumapping direction_id bigint null 0', '([^\s]+)'))
it shows only first word - isu_lib.directions_directions_isumapping,
but I need 'isu_lib.directions_directions_isumapping direction_id'
Another words - everything before second space.
How to change query?
Postgres 11 version

How about just using SUBSTRING():
SELECT SUBSTRING(col FROM '^[^ ]+ [^ ]*')
FROM yourTable;
Demo
The regex pattern used here says to match:
^ from the start of the string
[^ ]+ a non space term
a single space
[^ ]* another non space term, if it is available

Related

Regex to match specific string + optional space + 8 digits [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need a regular expression to validate strings with the prefix 'CON' followed by an optional space followed by 8 digits.
I've tried various expressions, I got tangled up and now I'm lost.
^(CON+s\?d{8})$
\bCON\b\S?D{8}
Syntax is off a bit
^(CON\s?\d{8})
( starts a capturing group
CON is exactly matched
\s matches any white space character and the ? makes it optional
\d{8} matches 8 digits
) ends the capturing group
You were pretty well off to start, Hope this helps :)
keeping in mind If there is no space, then there shouldn't be 8 more digits
^CON(\ \d{8})?
If the string you are looking for can be part of a larger string (note that in this case it may be preceded or followed by anything, even other digits):
CON\s?\d{8}
If the string must match in full, use ^$ to designate that:
^CON\s?\d{8}$
You can add variations to it, if say you want it to begin/end with a word boundary - use \bto indicate that. If you want it to end in a non-digit, use \D+ at the end, instead of $.
Finally, if you want the string to end with an EOL or a non-digit, you may use an expression like this:
CON\s?\d{8}(\D+|$) or the same with a non-capturing group: CON\s?\d{8}(?:\D+|$)

Swap two entries separated by comma in notepad++ [duplicate]

This question already has answers here:
notepad++ reg expressions to swap two values
(4 answers)
Closed 5 years ago.
I've been trying to swap entries in a file, separated by comma, but so far I have nothing. I've been reading that notepad++ can do this with regular expressions but i don't really know where to start.
To explain, I currently have this:
24.47343034934343,46.1923102403536
24.47343034934343,46.1923102403536
24.47343034934343,46.1923102403536
24.47343034934343,46.1923102403536
And what I need to achieve is this:
46.1923102403536, 24.47343034934343
46.1923102403536, 24.47343034934343
46.1923102403536, 24.47343034934343
46.1923102403536, 24.47343034934343
Put the following regex in find: (\s*)(.+?),\s*(.+) and replace with: $1$3, $2 (make sure the search mode is regex).
Explanation:
(\s*) First group - the initial whitespaces
(.+?) Second group - first number before ,
,\s* , and any number of whitespaces after it - no need to capture
(.+) Third group - second number
$1$3, $2 - replace with first group followed by third group followed by , followed by the second group.
You can also do with this regex ([.\d]+),([.\d]+) and do the replacement as $2,$1.

How to do regexp replace/search [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
I am following some instructions for data upload. I can't figure out what the following two points mean. Does anyone have any idea?
Regexp search/replace
search: 201([0-9])([0-9])([0-9])([0-9][0-9]) ([0-9])
replace:201\1\2\3\4 \5
Regexp search/replace
replace 20110401 with whatever year month day that is being fixed
^(.{462})
\120110401
Any decent regex tutorial will help.
() wrap groups that can be referenced later with \#. For example, \2 references the token matched by the second pair of parentheses.
[0-9] means any character between 0-9 inclusive.
^ is the left anchor (i.e., start of string or new line), and .{462} means any character, 462 times.

Perl regex to match phone numbers [duplicate]

This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 7 years ago.
Regex:
\b(\(\d{3}\)|\d{3})?[-.]?\d{3}[-]?\d{4}\b
My input file has two types of phone numbers. One, whose first 3 digits are enclosed in parenthesis and the other with no parenthesis.
Eg:
"(201)-450-4479" ,"234-345-3456"
I want to match both type of phone numbers using alternate operator.
Please suggest me. What modification is required for above mentioned expression to get the intended result?
\b matches at a word-nonword boundary. If such a boundary should appear before (, it must be preceded by a word character, not whitespace or nothing.
Cf.
print /\b\(/ ? 1 : 0 for '(', ' (', 'a(';
Remove the starting \b from the regex, or replace it with
(?x: \b | \s | ^ )
I'd use this:
(\(?\d+\)?\-\d+\-\d+)
or using the alternate operator:
(\d+\-\d+\-\d+|\(\d+\)\-\d+\-\d+)

Regex to validate letters numbers and specific special characters [duplicate]

This question already has answers here:
Regex for validating a string with pre-specified special characters
(3 answers)
Closed 8 years ago.
I have unsuccessfully be looking around the web for such a simple regex and can't seem to put it together.
I need a regex which allows any letter, numbers, whitespace and particular special characters only (# # $ & ( ) - _ /)
"Test #123 #Sample/test" is valid
"Test ^ £300" is not valid
Simply you could try the below regex,
^[\w\s##$&()\/-]+$
DEMO
^ Asserts that we are at the start.
[\w\s##$&()\/-]+ Matches one or more characters from the list.
$ Asserts that we are at the end.