Notepad++ regex get 2nd group - regex

I have a tex with 32k lines like this example
A01.2 Some Text
A01.3 some Text
A01.4 3Some Text
A02.0 [some text]
B02.1 Text .05 example
I need to replace white spaces with ';' symbol.
I tried (\S{3}\.\d)(\s) but notepad++ highlights/gets both groupsB02.1 with whitespace.
1st question: how do i disable 1st group, or take only 2nd
2nd question: is there another expression do find only this white space?
Here is the real example:

If you want to replace the whitespace by ;, so this B02.1 will be B02.1; using notepad++; since you're capturing the groups then use $ notation in the replace expression.
Find: (\S{3}\.\d)(\s)
Replace: $1;
$1 is for the first captured group.
Hope it helps,

You disable the first group simply not grouping it:
\S{3}\.\d(\s)
Otherwise, the look-behind may suite your case:
(?<=\S{3}\.\d)(\s)

Use a lookbehind so B02.1 won't get matched:
(?<=\S{3}\.\d)(\s)

Related

How to encase words with quotations?

I am currently trying to convert a list of 1000 words into this format:
'known', 'buss', 'hello',
and so on.
The list i have is currently in this format:
known
worry
claim
tenuous
porter
I am trying to use notepad++ to do this, if anybody could point me in the correct direction, that would be great!
Use this if you want a comma delimited list but no extra comma at the end.
Ctrl+H
Find what: (\S+)(\s+)?
Replace with: '$1'(?2,:)
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
(\S+) # group 1, 1 or more non spaces
(\s+)? # group 2, 1 or more spaces, optional
Replacement:
'$1' # content of group 1 enclosed in quotes
(?2,:) # if group 2 exists, add a comma, else, do nothing
Screen capture (before):
Screen capture (after):
How about replacing (\S+) with '$1'? Make sure your Regular Expression button is selected in the Find and Replace tool inside Notepad++
Explanation
(\S+) is regex for repeating non-whitespace characters (1 or more). Wrapping it in parenthesis puts it in a capture group which can be accessed in numerical order by using a dollar sign ($1).
'$1' will take that found text from the Find above and replace it with capture group #1 ($1) wrapped in single quotes '.
Sample
Input: known worry claim tenuous porter
Output: 'known' 'worry' 'claim' 'tenuous' 'porter'

Is there a regex that can search in a group of lines and replace one line within that group and keep the other words there

So for example if I have something like:
<House \>
windows
walls
<\House>
and I want to remove lets say walls how do I do that with regex or is there a better option than regex?
So I need it to look like:
<House \>
windows
<\House>
So how would I approach this with regex?
(?s)(?<=<Building \/>).*(?=<\/Building>) Will capture only what is between your two building tags.
(?s) allows . to match newline characters
(?<=<Building \/>) means your content should follow a block of text matching <Building />
.* is your content
(?=<\/Building>) just means that your content should be followed by </Building>
Demo
If you want to trim all that ugly white space, you could always use this pattern ((?s)(?<=<Building \/>)\s*(.*)\s*?(?=<\/Building>)) and refer to capture group 1.
What about:
Find: (<Building />\s+)floor(\s+</Building>)
Replace: \1corner\2

regex preserve whitespace in replace

Using REGEX (in PowerShell) I would like to find a pattern in a text file that is over two lines and replace it with new text and preserve the whitespace. Example text:
ObjectType=Page
ObjectID=70000
My match string is
RunObjectType=Page;\s+RunObjectID=70000
The result I want is
ObjectType=Page
ObjectID=88888
The problem is my replacement string
RunObjectType=Page;`n+RunObjectID=88888
returns
ObjectType=Page
ObjectID=88888
And I need it to keep the original spacing. To complicate matters the amount of spacing may change.
Suggestions?
Leverage a capturing group and a backreference to that group in the replacement pattern:
$s -replace 'RunObjectType=Page;(\s+)RunObjectID=70000', 'RunObjectType=Page;$1RunObjectID=88888'
See the regex demo
With the (\s+), you capture all the whitespaces into the Group 1 buffer and then, using $1 backreference, the value is inserted into the result.

Regex to get all character to the right of first space?

I am trying to craft a regular expression that will match all characters after (but not including) the first space in a string.
Input text:
foo bar bacon
Desired match:
bar bacon
The closest thing I've found so far is:
\s(.*)
However, this matches the first space in addition to "bar bacon", which is undesirable. Any help is appreciated.
You can use a positive lookbehind:
(?<=\s).*
(demo)
Although it looks like you've already put a capturing group around .* in your current regex, so you could just try grabbing that.
I'd prefer to use [[:blank:]] for it as it doesn't match newlines just in case we're targetting mutli's. And it's also compatible to those not supporting \s.
(?<=[[:blank:]]).*
You don't need look behind.
my $str = 'now is the time';
# Non-greedily match up to the first space, and then get everything after in a group.
$str =~ /^.*? +(.+)/;
my $right_of_space = $1; # Keep what is in the group in parens
print "[$right_of_space]\n";
You can also try this
(?s)(?<=\S*\s+).*
or
(?s)\S*\s+(.*)//group 1 has your match
With (?s) . would also match newlines

NOTEPAD++ REGEX How do I replace and remove a whitespace from $0

I'm using this regex:
\s[0-9]+ thd
It finds what I want perfectly. I want to remove the white space at the beginning. What should I put in the replace field?
Change the search text to \s([0-9]+ thd) and then the replacement id \1 or $1 depending on the type of regex.
Find:
\s([0-9]+ thd)
Replace:
$1
So if you using Notepad++ everything in parenthesis refers to section build from \ and number in Replace box.
Look at example:
Find: (\s)([0-9]+ thd)
Replace: \1\2
This give you back first \1 and second \2 section - nothing unusual, but when you live only \2 after replace you'll get only part found by ([0-9]+ thd)
Going further if you split your expression to (\s)([0-9]+)(\s)(thd) then you'll get 4 parts
This parts will be represented by \1\2\3\4 and if you need add something more to your output line:
for example added_text_before\1added_text_after in Replace will result merging added text and section found - practice because there is no hidden magic out there.
Remember that using regex in Notepad++ have some limitations (to long expression aren't read).