I have a file that includes such lines
111
112
113
I want to clone the lines and add a seperator between the numbers. Output should be as the following
111#111
112#112
113#113
How can I do it with notepadd++ by using regex replace
Find (.+)
Replace \1#\1
This will work
Related
I have a .txt file, with lots of lines in it. I have a procedure to fill up a database, using this textfile. But I only want to insert the lines where the string from position 67 to 70 matches 772. I cannot change the procedure to read the file, I have to change the file itself.
So in fact, I want to remove all lines from the txt-file where the string on position 67 to 70, doesn't match 772.
How can I get this done?
The following regex matches that string from position 67 to 70:
^.{66}772.*$
There are various ways to remove lines based on this regex, such as using grep with the -v flag. It depends on the tool you're using.
I have a text file like below. Every record has 12 fields which are separated by |, but there is no record delimiter like a newline, and every record starts with 555. I am trying to parse it with RegEx.
555|abc|user|2|20120914055204696|20120914055204718|0||||21|33555|def|udp|2|20120914055204696|20120914055204718|0||||22|33555|abc|user|2|20120914055204696|20120914055204718|0||||23|33
I tried with 555(\|.*?\|){12}(\d\d), but it did not work. Can anyone please help me with this?
You can use
555(?:\|[^|]*){11}(?=$|555)
See demo
It will match these records in the input string:
555|abc|user|2|20120914055204696|20120914055204718|0||||21|33
555|def|udp|2|20120914055204696|20120914055204718|0||||22|33
555|abc|user|2|20120914055204696|20120914055204718|0||||23|33
The regex 555(?:\|[^|]*){11}(?=$|555) matches:
555 - literal 555
(?:\|[^|]*){11} - 11 occurrences of | followed by any number of characters other than |
(?=$|555) - up to (but not returning as part of the match) end of string or 555.
555(?:\|[^|]*?){11}\d\d
You need to remove the second | .See demo.
https://regex101.com/r/sS2dM8/31
I am trying to match the tag numbers in a list of cats:
Abyssinian 987
Burmese a1a
Dragon Li 2B
987 Cat
cat 987 Toyger
cat A1A Siamese
1
The tag numbers for the list of cats would be:
987
a1a
2B
987
987
A1A
1
I've tried using the regular expression:
\b[0-9a-zA-Z]{1,3}\b
The problem is that it will match "cat" and "Li" (in Dragon Li). It should only match the tag number.
The requirements for a tag number are:
1-3 characters, it must contain at least one integer (0-9)
It can appear at any place in the string
As a side note, I am using Postgres regular expressions, which I think use POSIX regular expressions. (http://www.postgresql.org/docs/9.3/static/functions-string.html)
This works in PostgreSQL:
SELECT substring(cat FROM '\m(?=\w{0,2}\d)\w{1,3}\M') AS tag
FROM cat;
\m and \M .. beginning and end of a word.
(?=\w{0,2}\d).. positive lookahead
\w{1,3} .. 1-3 word characters
Assuming there is a single match in every string, substring() (without the "global" switch 'g') is better for the job than regexp_matches(), which would return an array (even for a single match).
substring() is also a bit faster.
SQL Fiddle.
You can use this regex:
\b(?=\w*?\d)\w{1,3}\b
Online Demo
Test: Using grep -P:
grep -oP '\b(?=\w*?\d)\w{1,3}\b' file
987
a1a
2B
987
987
A1A
1
I am trying to match the lines in following not input NOT containing "VelSign" (using Notepad++):
#MARKER VelSign 457.45 50 kmh
#MARKER IsBridge true
#MARKER TrafficSign 45
#MARKER TrafficLight 45 445 444 40
I am using the following regex:
^#MARKER (?!.*VelSign).*$
Doesn't seem to work. What am I doing wrong?
Make sure that you upgrade Notepad++ to version 6, as they changed quite a lot in the regex engine. Especially line breaks and lookarounds were a bit problematic in earlier versions.
Turn this:
^#MARKER (?!.\*VelSign).*$
Into this:
^#MARKER (?!.*VelSign).*$
You are escaping the * operator, which causes the match of a literal * instead of 0 or more ..
Also, make sure that you have checked the RegularExpression option (see the third radio button):
I would like to know a way to remove duplicate words or strings in a text file(not lines) using notepad++ regex find tool.
I only saw ways to remove duplicate lines using TextFx and that is not what i am looking for.
Example -
123 / 789
123 / 321
Removing 123 would result in
123 / 789
/ 321
I'm not familiar with Notepad++, but assuming it uses standard syntax, replace
\b(\w+)\b([\w\W]*)\b\1\b
with
$1$2