Why `\t*` will not match zero or more tabs? [duplicate] - regex

This question already has answers here:
Zero-Length regexes and infinite matches?
(2 answers)
Closed 6 years ago.
If you try on http://regexr.com/ the regex \t you get all the single tabs. But if you try \t* you get only on the beginning of the first line. Why?

If you use \t* only, then you trying to match nothing, one or more tabs. Nothing in regexp will match anything, so it won't work.
If you need to find one or more tabs, use \t+ instead.
To make your regexp work on all lines, use global setting. There is an example: http://regexr.com/3db4i

Related

Regular expression get only one match [duplicate]

This question already has answers here:
How to match multiple occurrences of a substring
(3 answers)
Regex match sequence more than once
(2 answers)
Closed 2 years ago.
I have problem with regular expression.
https://regexr.com/505i2
Somehow it find only one :heart: but it should find these words when it's beetwen : character.
So in this case it should be: :heart: , :smile: , :smile: , :heart:
Please help.
You are missing the global flag:
/\:([a-zA-Z]+\w)\:/g
You can just tick it from the flags button.
The global flag means that you want to mark all occurrences of your pattern. Without it, you just get the first match.

REGEX - How can I return text between two strings [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 3 years ago.
Link Regex101
I am using (FD.*?)FD however I am missing every second expression - see regex. Any ideas?
The trailing "FD" in your regex matches the "FD" in the input that starts the next "item" in the input text, so the entire next "item" is skipped, until it finds another "FD".
In a case like this, instead of specify .* followed by the pattern that starts the next item, you typically want to specify anything not including a pattern of FD.

WebStorm use Regex to add quotations around found matches [duplicate]

This question already has answers here:
Regex to replace string not in quotes in IntelliJ
(2 answers)
Closed 3 years ago.
Given the following array:
R991,U847,L239,U883,L224,D359,L907,D944,L79,U265,L107
I'd like to add quotation around each individual instance of a letter followed by a number of characters using the 'search and replace' function.
Now in the search function I can target all the instances using the Regex option, and using [A-Z]\d*.
Now for the replace value, how can I use a certain wildcard character to keep the same Regex value intact?
Example:
The end result should be:
"R991","U847","L239","U883","L224","D359","L907","D944","L79","U265","L107"
Note: As a quick fix I searched for each , and replaced that with "," which almost fixed it entirely. But I'm wondering for more complex cases you could use a wildcard.
Search for: ([A-Z]\d+)
Replace by: "$1"
https://www.jetbrains.com/help/webstorm/tutorial-finding-and-replacing-text-using-regular-expressions.html#capture_groups_and_backreference

Regex pattern for String not ending in a sequence [duplicate]

This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 4 years ago.
I am trying to find all strings not ending with the sequence -6X.
What i'm trying to do is compare the value of an xml tag with a sequence.
If it matches then do some stuff.
However I am unable to do so. I want to achieve this without any lookaheads or lookbehinds.
I've tried using .*[^-6X]
However this does not work for strings ending in - or -5 .
I want to ignore strings ending in -6X only and every other pattern should work.
Thanks in advance for your help
This matches Strings NOT ending with -6X:
.*?([^-]..|.[^6].|..[^X])$
https://regex101.com/r/omwkQ3/2

Regexp: multiline-match anything between ( and ); [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 6 years ago.
Here's my current setup:
(image showing regexr-highlighted strings)
My regexp match is Skript\.register(effect|expression|event|condition)\((.*)\)\;
Basically, I want to match all methods from a source code file that start with Skript.registerwhatever.( and end with );, but the problem is the code can go multiline. If I change (.*) to ([\s\S]*), it completely wrecks and matches everything until the very last );.
You need a lazy quanitfier: *?
\(([\s\S]*?)\)
And if your string contains nested parenthesis:
(?'parens'\((?:[^\(]|\g'parens')*?\))
You need to escape parenthesis in regex because they are reserved symbols. Try \(.*\)