Can I Find and Replace html links using Notepad++? - regex

I want to find and replace a bunch of links, except I don't know how to format the search expression. I want to find the links that look like this:
http://website.com/test.php?id=930&name=hello
The 930 and hello are the variables that are different.
edit: I tried "http://website.com/test.php?id=.*&name=.*"> but it selects a bunch of stuff after that too like img src on that line etc
I tried using [^"]* or (.*?) instead of .* but it says it can't find the text :(

Notepad++ seems to have limited regex. It doesn't use the nongreedy variants (.*?) and some anchors for word boundaries like \b, \Z are also not working.
I think this will help you:
http://website.com/test.php?id=\d*&name=\w*
insted of searching for .* which will also match to whitespaces, use \d* this will find only numbers and \w*, this will find only letters.
If the name can contain other things than letters than use this
http://website.com/test.php?id=\d*&name=[\w\d]*
and add into the [] all you need to match. in my example it will match letters and numbers.
Hint for future questions: Think about your tags. If you would have used the tag "regex", you would have gotten 5 answers within minutes for your question.

Related

regex to remove dash from phone numbers

I have lines like this
TEL;TYPE=CELL:343-454-1212
TEL;TYPE=CELL:34345-121212
TEL;TYPE=CELL:123456789
I need to remove dashes from them using VSCode.
So far I came with:
Search With : (TEL;TYPE=CELL:\d*)-(\d*)
Replace With : $1$2
I have to search and replace multiple times (In this case two times) to get the expected output. This is mainly because I do not know how many dashes are there.
Is there any regex which I can use to accomplish, what is being done here in single go?
Wrap the number in parenthesis like this so you can restore it, removing the -
-([0-9])
replace with $1
Or
Just repeat this find replace, till they are all removed:
find: (TEL;TYPE=CELL:[^-]*)-
replace: $1
I tried this limited solution.only for 2 or 3 dash.
Search with: (\d+)-(\d+)(?:-(\d+))?
Replace with: $1$2$3
but in the comment that said replace dashes with empty str also a good solution.
Visual Studio Code search and replace in the current document feature (not the one to replace in files) supports regexps with variable-width lookbehind patterns, so you can use
(?<=TEL;TYPE=CELL:[\d-]*)-
See the regex demo. Details:
(?<=TEL;TYPE=CELL:[\d-]*) - a position that is preceded with TEL;TYPE=CELL: and then zero or more digits or hyphens
- - a hyphen.

What's the regex to match a string except it has a $ dollar sign in it?

So basically, I have a text like this:
secret(mapOf("path" to "config/info"))
secret(mapOf("path" to "config/data/${rootProject.name}"))
prefix(mapOf("path" to "config/${rootProject.name}", "format" to "${rootProject.name.replace('-', '_')}"))
I want to match a path like config/info and not to match paths which contain variables (have dollar signs in them). I came up with this ((?:'|\")config/.+(?:'|\")) but it also matches the others.
How can I exclude strings with dollar signs?
What you are looking for (if I fully understand your question) is this one:
(['\"]config/[^$]+['\"])
Explanation:
I used ['"] instead of (?:'|\") I believe it will make your regex
readable and simple to understand in the future.
Also using [^$]+ instead of .+ is the key to solve your issue, .+ will match anything however [^$]+ will match anything as long as it's not $.

RegEx - find all occurrences of a word and exclude certain words that contain it

searching all over couldn't find a solution and also am breaking my head with this for a while already.
I want to search for all occurrences (words not sentences containing) of word end but exclude certain words from being found - that I want to specify myself.
For example, I am interested in all possible combinations of (should match):
end
ended
date-end
hasEnded
end_date
but I want to exclude all these words for example (should not match):
render
appendTo
extend
renderGrid
while not selecting the whole lines, only the matching words.
The closest I could get is this regex: (?!extend|appendTo|render|renderGrid)(\b.*end.*\b) but this selects the whole lines and more-over doesn't work in Search in files in IntelliJ IDEs which is frustrating.
Anybody willing to improve and make it working in Search in files in IDEs?
You could match 0+ times a non whitespace char \S* at both ends or use a character class [\w-]* and specify what you would allow to match.
You might omit the capturing group and get the matches only.
(?!extend|append|render|renderGrid)\b\S*end\S*\b
Regex demo

REGEX - How to find two hyphens in a filename?

I'd like to search for filenames that contain two hyphens (only). Some filenames have one hyphen, I just want the one's with two hyphens in the name:
THIS: some text - more text - yet more.txt
NOT THIS: some text - more text.txt
The hyphens are always surrounded by a space, FWIW.
I tried using (.*) - (.*) - (.*) and a couple variants, but the results aren't what I am looking for. I either get nothing or filenames with just one hyphen when I try various combinations.
I know this is an obvious one, but I have tried wading through regex tutorials concerning greedy, look aheads, etc. but can't for the life of me solve this. Can anyone help? I'm not looking for just the solution--I'd like to understand what I'm doing wrong in the regex syntax.
You can use this regex,
^[^-]*(?:-[^-]*){2}$
This when written in expanded form will look like this,
^[^-]*-[^-]*-[^-]*$
Which is how you wanted it, but I've compacted it by using quantifier to restrict the occurrence of hyphen to just two only.
Demo
If you want to extend your regex, just change .* to [^-]* to make your regex this, otherwise .* will match additional hyphens too leading to unexpected match results.
^([^-]*) - ([^-]*) - ([^-]*)$
Notice you should use start ^ and end $ anchors to make the filename match whole regex.
Demo with your modified regex

How to exlude certain word on regex

I have a text document that I need to modify. Most of the words are seperated by "-" (minus) character.
So in sublime text, I tried this pattern:
(\w+)\-(\w+)
This pattern works perfectly fine but there is one word that has "-" (minus) character naturally in the document. (Eg: foo-bar)
So I need a pattern that finds all minus seperated words but exludes "foo-bar"
Sorry if this question asked before but I couldn't find the answer I needed
You can use a negative look-ahead (with optional i switch to match words in a case-insensitive way):
(?i)(?!\bfoo\-bar\b)\b(\w+)-(\w+)\b
Mind that this will only work with non-overlapping matches.
See example:
If you want to replace a hyphen with space in cases I provided in the screenshot, you can use (?!\bfoo\-bar\b)\b(\w+)\-(?=\w) search regex and replace with $1 (result: go there now):