Remove parenthesis but keep number [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm editing a large MS Word document (113 pages) that has a lot of numbers surrounded by parenthesis, ie: (1) (2) (3) etc. The numbers are used for references which are given at the end of each 'chapter' and so they need to be kept.
How can I remove the parenthesis but keep the numbers which, in turn, need to turned into superscript?
Is there a way of using regexp to do this?
Thanks in advance for any help you can give.

Do a Find and Replace in Word, using the following settings:
Find: \(([0-9]{1,})\)
Replace: \1
Format: superscript
The formatting option for the "replace" is at the bottom of the "Find and Replace" dialog.
Regex breakdown:
The \( and \) surrounding the expression are the literal parens you are matching.
The inner ( and ) are grouping parens to capture the text that matches the pattern inside.
[0-9]{1,} matches one or more digits
In the replace pattern, \1 refers back to the first matched group (in this case, there's only one: the digits inside the parens).

Related

Block Youtube ads [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
I'm trying to block the annoying youtube ads with pihole but unfortunately it doesn't work for me. The following is not viewed at all:
(rr[\d]{1}---[\s]{2}-[\s]{8}-[\w]{4})\.googlevideo\.com
Has anyone had similar experiences?
Examples look like this
rr1---sn-8xgn5uxa-quhl.googlevideo.com
rr1---sn-8xgn5uxa-quhl.googlevideo.com
rr3---sn-8xgn5uxa-quhz.googlevideo.com
rr6---sn-8xgn5uxa-quhl.googlevideo.com
Using [\s]{2} in the pattern (which can be written as \s{2} matches 2 whitespace chars, but in the example data there is sn
The single meta characters in this case do not have to be placed between square brackets.
Looking at some documentation on this page \w \s and \d are not supported.
You might use
rr[[:digit:]]---sn-[[:alnum:]]{8}-[[:alnum:]]{4}\.googlevideo\.com
The pattern matches:
rr[[:digit:]] Match rr and a single digit
---sn- Match literally
[[:alnum:]]{8} Match 8 alphanumerics
-[[:alnum:]]{4} Match - and 4 alphanumerics
\.googlevideo\.com Match .googlevideo.com
See a regex demo.
Pi-Hole documentation does not mention the usual abbrevations for character classes (like \d, \s or \w you used).
If you replace your character classes with the ones from the Pi-Hole documentation you end with
(rr[:digit:]{1}---[:space:]{2}-[:space:]{8}-[A-Za-z0-9_]{4})\.googlevideo\.com
Probably the \s is not what you originally wanted, as your examples contain letters there instead of spaces. And \w includes an underscore, that does not appear in your examples. Also a {1} can be skipped.
So I would suggest this expression:
(rr[:digit:]---[:alnum:]{2}-[:alnum:]{8}-[:alnum:]{4})\.googlevideo\.com
If you don't need the hostname-part for further processing, you could remove the group marker () around it.
This pattern matches all your samples but it may be too tight?
rr\d---sn-8xgn5uxa-quh\w.googlevideo.com

Matching up to special character [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to capture something until a , (comma).
Example payload1: AgentBrand: Internet Explorer,
Example Payload2: AgentBrand: OutlookPlug-in,
From the above payload I need to capture whatever coming after AgentBrand:
until the command (,).
I have Tried AgentBrand:\s+(\w+\s+\w+) .But this will be become a lengthy regex.
Thanks
The current regex that you are using - AgentBrand:\s+(\w+\s+\w+) will only catch cases where you have at least two words separated by a space and even in those cases it will only pick up the first two words (when there may be more).
A better regex to use would be - AgentBrand:\s*(.*?),
what this does is
AgentBrand: - looks for the string 'AgentBrand:'
\s* - matches zero or more space characters
(.*?) - captures any characters non-greedily [takes minimum matches to satisfy result]
, - looks for a comma at the end
Also as a note, the length of a regex is not always a good reason to avoid using one. The regex in your example is not that long and is quite simple and could be freely if it met all your requirements. Looking at the complexity of a regex is a better choice

Notepad++ ignoring end delimiter of RegEx [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a JSON file. There is some information I want to delete and the process would be quite tedious to be done manually, and incredibly quick to perform through RegEx.
I want to find matches starting by, let's say, "abc" (including quotes), composed by any set of characters (including conflicting ones like brackets), and ending by , (the comma character), new line and " (left quote character).
Although RegEx is not my best strength, I have read several questions that could be related, like this one, and tried out several patterns, being this the one in which I believe the most:
"abc"(.*),^"
But it doesn't work properly. It starts fine, but the part after the (.*) is completely ignored, so the rest of the text in the document is selected instead of only what I requested.
^ doesn't mean newline. It's a "zero-length anchor" that matches the position before the first character of a line.
You want something like
"abc"(.*),\r?\n"

How to start a RegEx statement at the 2nd position of a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string
.HACK G.U. VOL. 1 REBIRTH
I'm using a tool that allows me to specify a RegEx statement that can be used in a replace operation.
I want the RegEx to find all the periods "." that start after the 1st position. The replace operation should return the following.
.HACK GU VOL 1 REBIRTH
Thanks
The following will do the trick:
(?<!^)(\.)
per http://rubular.com/r/w1apzTZLPk
Since Javascript doesn't support negative lookbehind, this can't be done in Javascript, but there are alternatives as discussed in http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
One approach in this case would be to capture the previous character and replace it with the same content as part of the replacement process, as in:
(.)(\.)
Note: You don't need to use a capture group for the matching of the literal . in either of the above. I just used that technique to highlight the match in Rubular.

Regex for two digit number followed by . for find and replace in vim [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to find out following string pattern in vim and replace it with some thing else. Can you please tell me regex for the same.
1.
11.
20.
21.
99.
basically one / two digits followed by dot.
I think you could do something like the following (I'm not very experienced with VI so there might be a better way)
:%s/\d\+\./MyString/gc
So that's essentially using \d\+\. to search for numbers appearing one or more times followed by a ..
MyString is your replacement string.
:%s is the substitute command, :s would just search the current line.
/gc looks for the match as many times as it appears on the line (g), and asks for confirmation before each replacement (c).
Tried this?
[^0-9][0-9][0-9]\.
Or have you tried it and it didn't work?
It has an issue though of three digits and a dot, i.e. "123." will also be captured
The regex for 1 or 2 digits followed by a dot is:
\<\d\d\?\.
The "word boundary" \< precludes 3 digits (and a dot), which would be allowed without it (the last two digits of a 3-digit number would match).
To replace using this tegex in vi:
s/\<\d\d\?\./foo/g