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

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.

Related

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

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

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+|$)

How to extract a particular word after 7th slash in a path using regex [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 4 years ago.
I have different paths in a column like below:
'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/Toothpaste/Variant Data/AUSTRIA_SHG_VARIANT_8.csv'
'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/ManualTB/Variant Data/AUSTRIA_SHG_VARIANT_7.csv'
'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/MouthWash/Variant Data/AUSTRIA_SHG_VARIANT_9.csv'
I want Toothpaste from 1st path, ManualTB from 2nd, and MouthWash from 3rd.
There are many more paths around 30 every from every paths I want the word from 7th slash.
How can I do this using regex?
You can use the following regex:
(?:\/([^\/\n]*)){7}
Check Regex Demo
Required keywords would be in capture group 1
You can match any optional characters followed by a slash and capture the word following it by using this regex,
(?:.*?\/){7}(\w+)
Explanation:
(?:.*?\/){7} --> Non capture group matching any optional characters followed by / seven times
(\w+) --> Capture the following word in group 1
Demo
Let me know if this works fine for you.

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.

What does the regular expression ^(\d{1,2})$ mean? [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 8 years ago.
I am trying to understand what the regular expression ^(\d{1,2})$ stands for in google sheets. A quick look around the regex sites and in tools left me confused. Can anybody please help?
^ Asserts position at start of the string
( Denotes the start of a capturing group
\d Numerical digit, 0, 1, 2, ... 9. Etc.
{1,2} one to two times.
) You guessed it - Closes the group.
$ Assert position at end of the string
Regular expression visualization:
^ - start of a line.
(\d{1,2}) - captures upto two digits(ie; one or two digits).
$ - End of the line.
It means at least one at most two digits \d{1,2}, no other characters at the beginning ^ or the end $. Parenthesis essentially picks the string in it i.e. what ever the digits are
^ matches the start of the line
The parens can be ignored for now..
\d{1, 2} means one or two digits
$ is the end of the line.
The parens, if you need them, can be used to retrieve the digit(s) that were found in the regex.