Regex for remove everything after "_" in all anchor Tag [closed] - regex

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 want any regex to remove everything after underscore in all anchor Tag e.g
input: Text
Output Text

Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,
(<a\s+[^>]*?href=["'][^']*?)_.*?(["'])
and replace it with \1\2 (or $1$2 as per the language)
Check the demo
You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.

Related

Extract the required part from same type of URLs in notepad+++ by regex [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 11 months ago.
Improve this question
I have a list of URLs from same website. How can I extract a particular part of them using regex in Notepad++?
Here is a part of the URLs:
https://www.example.in/example/MT60B2G8HB-48BA-TR?qs=iLbezkQI%252BsgqYFd1yfooJw%3D%3D
https://www.example.in/example/AT25L128A-MHE-T?qs=IS%252B4QmGtzzoXQyQfwYv36A%3D%3D
Output should be MT60B2G8HB-48BA-TR & AT25L128A-MHE-T from all the similar type of URLs.
A short alternative as usual
Find:^.*/(.*?)\?.*
Replace with:$1
If all URLs have the same url, path up until the last part & do always have GET-parameters (using ?), then you can use this:
"(?<=https://www.example.in/example/)[^?]+"
# match any string that has https://www.example.in/example/ before it until the first ?
If it is optional whether the url has GET-params:
"(?<=https://www.example.in/example/)[^?\s]+"
# match any string that has https://www.example.in/example/ before it until the first ? or whitespace/linebreak
the following will allow you to search for the pattern (in regex mode of course) :
(?<=https://www.example.in/example/).*(?=\?)
(?<=...) is called positive lookbehind and must be a fixed pattern positioned before what you are looking for
(?=...) is called positive lookahead and must be a fixed pattern positioned after what you are looking for (here the first '?' escaped with '\')
If you want to replace the pattern then you can simplify to this.
Find what : https://www.example.in/example/(.*)\?.*
Replace with : $1

How to remove certain prefix using regex [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 1 year ago.
Improve this question
My User data can come in any of the following 3 ways -
user="dc\AAA", user="BBB", user=CCCC,
Now, the bottom two I am able to extract it easily but issue comes when user data has an additional prefix of "dc" to it
I am trying to remove that prefix using regex and format all user data in single regex as below, but the unable to do so
user=AAA user=BBB user=CCC
Can someone please help.
This regex should do the work: (?:.*\\)?(.*).
Let's split this regex into parts:
(?: ) - A non-capturing group
.*\\ - Any characters many times, trailing by backslash
? (after the brackets) indicates the data in the brackets may occur once or not at all
(.*) Any characters
Overall - Capturing the data after the backslash if exists
I suggest using this amazing website for trying regex

How to remove comma at end of extracted value? [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 2 years ago.
Improve this question
I am having the following String
{'Sample': '#it{tq}', 'Yield': 0.011063753491221462, 'Error': 0}
and I would like to extract the value from 'Sample', that means '#it{tq}'. I tried that using a regular expression: 'Sample':(\s*.+?\s)
but its giving me: '#it{tq}', including that comma at the end. Does anyone know how to erase the comma at the end?
this regular expression should do the job.
regex: 'Sample':\s*('[^']*')
https://regex101.com/r/DL5Ltq/2
how about using this:
'Sample': '(.*?)',
beware that the regex in the accepted answer cannot process the case having single quote escape text inside the capture group like this: {'Sample': '#it'{tq}'}.
If you use (.*?), it greedily process any single character inside two single quote.

Is there a Notepad++ RegEx to remove everything but digits and spaces? [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 2 years ago.
Improve this question
Is there a RegEx to remove everything but digits and spaces in Notepad++?
I know there is one that removes only digits but i dont need that.
PS: I do not want the lines to be removed
Example:
11234123 alex-james
1412412 mmafsmasdas
After regex:
11234123
1412412
As the pattern use [^\d ]+. Almost what Poul Bak proposed, but change * into +, i.e. the sequence of chars to match should be non-empty.
There is no point in searching for an empty string and replace it with another empty string.
correction:
try this:
([^0-9| ]+)
this will surely work!!!
open the file in notepad++ press CTRL+H check the box with search mode regular expression and put in the above regex and click replace all

Using regular expressions to locate line comments without spaces [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I tried to find all comments beginning with // that don't have a space after the slashes.
I want to select only the slashes. No whitespace or text before that, no whitespace or text after that.
So far I've reached to [\s].(\/\/(?! )) but it catches the space before the slashes as well.
Basically I wanna make sure my line comments have a space after the slashes.
I'm trying to do this either in JavaScript or in any text editor.
Since javascript doesn't have the lookbehind feature, you can't.
The workaround (for instance, in a replacement context) is to use a capture group for the character before the two slashes and to start the replacement string with a reference to this group ('$1replacement'):
([^/\s]|^)//(?! )
You can use the following regex:
.*(\/\/(?= )) demo
The idea is to use positive lookahead and capture the // iff it is followed by a space.
EDIT: Just noticed that your question is contradictory. So if you want to capture if the // is not followed by a space, use this: .*(\/\/(?=\S)). Otherwise use the one above.