Exact text (not entire lines) matched by pattern in Notepad++ (npp) [duplicate] - regex

If i have a big text, and i'm needind to keep only matched content, how can i do that?
For example, if I have a text like this:
asdas8Isd8m8Td8r
asdia8y8dasd
asd8is88n8gd
asd8t8od8lsdas
as9ea9ad8r1n88r8e87g6765ejasdm8x
And use this regex: [0-9]([a-z]) to group all letters after a number and replace with \1 i will repace all (number)(letter) to (letter) (And if i want to delete the rest and stay only with the letter matched)?...
Converting this text to
ImTr
y
ing
tol
earnregex
How can i replace this text with grouped and delete the rest?
And if i want to delete all but no matched?
In this case, converting the text to:
8I8m8T8r
8y8d
8i8n8g
8t8o8l
9e9a9r1n8r7g5e8x
Can i match all that is not [0-9]([a-z])?
Thanks! :D

You may use the following regex:
(?i-s)[0-9]([a-z])|.
Replace with (?{1}$1:).
To delete all but non-matched, use the (?{1}$0:) replacement with the same regex.
Details:
(?i-s) - an inline modifier turning on case insensitive mode and turning off the DOTALL mode (. does not match a newline)
[0-9]([a-z]) - an ASCII digit and any ASCII letter captured into Group 1 (later referred to with $1 or \1 backreference from the string replacement pattern)
| - or
. - any char but a line break char.
Replacement details
(?{1} - start of the conditional replacement: if Group 1 matched then...
$1 - the contents of Group 1 (or the whole match if $0 backreference is used)
: - else... nothing
) - end of the conditional replacement pattern.

Related

Removing everything but the regex result (Notepad++) [duplicate]

If i have a big text, and i'm needind to keep only matched content, how can i do that?
For example, if I have a text like this:
asdas8Isd8m8Td8r
asdia8y8dasd
asd8is88n8gd
asd8t8od8lsdas
as9ea9ad8r1n88r8e87g6765ejasdm8x
And use this regex: [0-9]([a-z]) to group all letters after a number and replace with \1 i will repace all (number)(letter) to (letter) (And if i want to delete the rest and stay only with the letter matched)?...
Converting this text to
ImTr
y
ing
tol
earnregex
How can i replace this text with grouped and delete the rest?
And if i want to delete all but no matched?
In this case, converting the text to:
8I8m8T8r
8y8d
8i8n8g
8t8o8l
9e9a9r1n8r7g5e8x
Can i match all that is not [0-9]([a-z])?
Thanks! :D
You may use the following regex:
(?i-s)[0-9]([a-z])|.
Replace with (?{1}$1:).
To delete all but non-matched, use the (?{1}$0:) replacement with the same regex.
Details:
(?i-s) - an inline modifier turning on case insensitive mode and turning off the DOTALL mode (. does not match a newline)
[0-9]([a-z]) - an ASCII digit and any ASCII letter captured into Group 1 (later referred to with $1 or \1 backreference from the string replacement pattern)
| - or
. - any char but a line break char.
Replacement details
(?{1} - start of the conditional replacement: if Group 1 matched then...
$1 - the contents of Group 1 (or the whole match if $0 backreference is used)
: - else... nothing
) - end of the conditional replacement pattern.

Regex to check number of spaces after full stop - Strictly 2 required

I need to check occurrences where I have put one whitespace after a full-stop, and replace it by 2 spaces. I have the Regex for it, but Atom seems to call in invalid.
(?<=\.|\") {1,}(?=[a-zA-Z])
Conditions:
1 spaces after period.
If period in with a closing double quote, then 1 space after the quote.
The above regex works perfectly for my conditions however Atom is not able to validate it. I need to use it for existing files.
You may use
([."]) ([a-zA-Z])
and replace with $1 $2. See the regex demo and a regex graph:
Details
([."]) - Group 1 (its value is referred to with $1 backreference from the replacement pattern): . or "
- a space (use \s to match any whitespace)
([a-zA-Z]) - Group 2 ($2): an ASCII letter.

Remove all text except the RegEx pattern (ABC|123|XYZ)(\w+) in Notepad++ [duplicate]

If i have a big text, and i'm needind to keep only matched content, how can i do that?
For example, if I have a text like this:
asdas8Isd8m8Td8r
asdia8y8dasd
asd8is88n8gd
asd8t8od8lsdas
as9ea9ad8r1n88r8e87g6765ejasdm8x
And use this regex: [0-9]([a-z]) to group all letters after a number and replace with \1 i will repace all (number)(letter) to (letter) (And if i want to delete the rest and stay only with the letter matched)?...
Converting this text to
ImTr
y
ing
tol
earnregex
How can i replace this text with grouped and delete the rest?
And if i want to delete all but no matched?
In this case, converting the text to:
8I8m8T8r
8y8d
8i8n8g
8t8o8l
9e9a9r1n8r7g5e8x
Can i match all that is not [0-9]([a-z])?
Thanks! :D
You may use the following regex:
(?i-s)[0-9]([a-z])|.
Replace with (?{1}$1:).
To delete all but non-matched, use the (?{1}$0:) replacement with the same regex.
Details:
(?i-s) - an inline modifier turning on case insensitive mode and turning off the DOTALL mode (. does not match a newline)
[0-9]([a-z]) - an ASCII digit and any ASCII letter captured into Group 1 (later referred to with $1 or \1 backreference from the string replacement pattern)
| - or
. - any char but a line break char.
Replacement details
(?{1} - start of the conditional replacement: if Group 1 matched then...
$1 - the contents of Group 1 (or the whole match if $0 backreference is used)
: - else... nothing
) - end of the conditional replacement pattern.

Regular expression for substitute a string with another

I have this two lines of text, that I want to manipulate using Regular Expression and substitute:
Obj.FieldNameA = Reader.GetEnumFromInt32<ClassName>(QueryGenerator,nameof(Obj.));
Obj.FieldNameB=Reader.GetTrimmedStringOrNull(QueryGenerator,nameof(Obj.));
Attached on the first Obj. there is a Field name, so in this case they are FieldNameA,FieldNameB
I want to attach these values to the second Obj. found on the same line, so the text should become:
Obj.FieldNameA = Reader.GetEnumFromInt32<ClassName>(QueryGenerator,nameof(Obj.FieldNameA));
Obj.FieldNameB=Reader.GetTrimmedStringOrNull(QueryGenerator,nameof(Obj.FieldNameB));
I have tested this very simple (and wrong) regex:
Obj\.(\w*).*\n
With substituition as $1
But I don't know how to use substitution...
Sample code here
Some Notes:
After FieldNameA there is always an equal sign that could be preceded or followed by a space.
Before the second Obj. there could be any character, including < ( etc...
Could this be achieved?
You may use
Find: (Obj\.(\w+).*\(Obj\.)\)
Replace: $1$2)
See the regex demo.
You may also add ^ to the start of the regex to match only at the start of a line/string.
Details
^ - start of string
(Obj\.(\w+).*\(Obj\.) - Group 1 ($1 in the replacement):
Obj\. - Obj. text
(\w+) - Group 2 ($2): 1 or more word chars
.* - any 0+ chars other than line break chars as many as possible (you may use .*? to only match the second Obj. on a line, your current input only has two with the second one closer to the end of a line, so .* will work better)
\(Obj\. - (Obj. text
\) - a ) char.

Regex and multiple matches [duplicate]

If i have a big text, and i'm needind to keep only matched content, how can i do that?
For example, if I have a text like this:
asdas8Isd8m8Td8r
asdia8y8dasd
asd8is88n8gd
asd8t8od8lsdas
as9ea9ad8r1n88r8e87g6765ejasdm8x
And use this regex: [0-9]([a-z]) to group all letters after a number and replace with \1 i will repace all (number)(letter) to (letter) (And if i want to delete the rest and stay only with the letter matched)?...
Converting this text to
ImTr
y
ing
tol
earnregex
How can i replace this text with grouped and delete the rest?
And if i want to delete all but no matched?
In this case, converting the text to:
8I8m8T8r
8y8d
8i8n8g
8t8o8l
9e9a9r1n8r7g5e8x
Can i match all that is not [0-9]([a-z])?
Thanks! :D
You may use the following regex:
(?i-s)[0-9]([a-z])|.
Replace with (?{1}$1:).
To delete all but non-matched, use the (?{1}$0:) replacement with the same regex.
Details:
(?i-s) - an inline modifier turning on case insensitive mode and turning off the DOTALL mode (. does not match a newline)
[0-9]([a-z]) - an ASCII digit and any ASCII letter captured into Group 1 (later referred to with $1 or \1 backreference from the string replacement pattern)
| - or
. - any char but a line break char.
Replacement details
(?{1} - start of the conditional replacement: if Group 1 matched then...
$1 - the contents of Group 1 (or the whole match if $0 backreference is used)
: - else... nothing
) - end of the conditional replacement pattern.