|
What can be the RegEx for matching all spaces in quotes but not quotes..
Example: "This is testing text"
My RegEx: (?<=\")\s+(?=\")
The above RegExp is not matching all spaces..
|
|
|
|
|
The \s+ in that regex will only match a single string of one or more consecutive whitespace characters, not "all spaces"
So your regex would match "This test" or "This test" but not "This is testing"
There are lots of online regex builders and analysers, which I suggest you seek out.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Sorry,
do you suggest me a regex to find in a page not properly closed href tags, like this?
<a href="https://www.sito.it/" target="_blank" rel="noopener"property</a>
In practice, the final ">" is missing. Can you suggest a regex that can detect this?
Thanks and good job
|
|
|
|
|
|
Ok Richard,
thaks a lot
|
|
|
|
|
|
|
The commonest way that people solve this for browsers that don't support this is to think in reverse. In other words, you reverse the string and the regular expression so that all you end up testing is the negative regular expression, rather than a lookbehind. This[^] is a great resource.
|
|
|
|
|
My Customer number is in the pattern : 88765
ie. 5 digits alone...
using regex i have to validate if there are any characters and special characters in the customer number. Incase there are any characters (eg: 8AB90) or special characters then my string is invalid.
Please help me with the RegEx for the same.
|
|
|
|
|
poornima sadasivan wrote: validate if there are any characters and special characters in the customer number. An easier way it to check to make sure all characters are numbers. This uses LINQ. For example:
return strVar.All(char.IsDigit);
|
|
|
|
|
Following should do it in perl, java and C#.
^[0-9]{5}$
|
|
|
|
|
Hello -
I have the following string:
[ CmdAV=show CmdArgAV=policy-map CmdArgAV=system CmdArgAV=type CmdArgAV=network-qos CmdArgAV=<cr> ]
Is it possible to use regex to leave only:
show policy-map system type network-qos <cr>
I don't need the [,], or CmdAV or CmdArgAV.
|
|
|
|
|
This should do the trick:
/C\w+=|[[\]]/g
|
|
|
|
|
Great, this does work. Thank you!
Is it possible to capture the remained words into a single group?
|
|
|
|
|
Hello,
I have a question on regex: Is it possible to match for certain characters (and replace them) in only a part of a string? E. g.
str="I want to solve this problem"
I now want to match all spaces after the first occurence of the letter, say, "v". I know I can filter the whole part of the string after (and including) the first v with the regex "v.*", but how to match the spaces only in that part?
Thank you!
|
|
|
|
|
Depends on the regex engine you're using.
For example, in C#, you can use a zero-width positive look-behind assertion[^]:
Regex re = new Regex("(?<=.*v.*)\s+");
string[] parts = re.Split("I want to solve this problem");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, Richard, for your answer!
I am using regex with javascript, developing for popular browsers.
So, if I understand correctly, your code splits the string into 3 parts, the first part being everything until the first space after the first "v", the other parts being the rest of the string split by spaces. I am sure that will work.
Well, what I was looking for - this is a more theoretical and general question - is there an operator you can use in regexes which does something like "apply the following only to the previously matched part"? For example:
/v.*#c/g
Explanation: The first part of the regex is "v.*" which means: Match the part of the string after the first v. The second part is "c", which will match every c. Now, is there an operator (here symolized by #) between the 2 parts of the regex, which means: "Apply the part after this operator ("c") to the result of the part before the operator ("v.*)"? It is like: Do a secondary match inside the primary match.
Sorry, English is not my native language, but I still hope, I could make my point clear.
Thank you.
|
|
|
|
|
Look-behind is the way to go:
(?<=Y)X matches X , but only if there's Y before it
Demo[^]
It's supported in the Javascript regex engine for most modern browsers:
Can I use... Lookbehind in JS regular expressions[^]
The only hold-outs are Internet Explorer - which even Microsoft agree should not be used any more - and Safari.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great, that was exactly what i was looking for, thank you so much, Richard!
So, to solve the problem from my original posting, that is to match all spaces after the first "v" in the string "I want to solve this problem", this Regex works:
/(?<=v.*) /g
|
|
|
|
|
Hi Would like to know if it's possible to get only the first match for this regex
^ \(SQL\)Max Duration..* ([0-9]+[0-9])( \([0-9][0-9][0-9][0-9])
I was able to isolate the value in second group but I am only interested to get the first match.
(SQL)Max Duration.. 1132 (2021-02-21 07:17:46:095)
(SQL)Std. Dev...... 3.36
(SQL)Max Duration.. 13 (2021-02-21 07:05:43:582)
|
|
|
|
|
Can you explain more what you're trying to do? Also, what tools/language are you using?
|
|
|
|
|
Hi there:
Suppose I have a string with "1: a string, 2: other 5 string, 3: something 8; else", what would be the regex pattern to obtain "1,2,3" as a result
Thank you in advance,
Rafael
|
|
|
|
|
You don't say what environment you are working in, so it's hard to give you useful code.
However, you can probably get what you want by either doing a search & replace operation, possibly repeated, or by using some kind of "regex iterator" approach.
For C++, it would be a regex iterator (iterate over all the matches of THIS pattern in THAT string). For something like Python it would be find all occurrences of THIS pattern in THAT string.
In order to drop the "8;" from your example sentence, you'd want to provide a better pattern than just "some digits." Instead, use something like /(\d+):/ to match on one-or-more digits followed by a colon. You want to capture the digits, not the colon.
If you can just iterate over all matches in the string, that will probably be enough. If you're doing sed or some other editor, you'll have to search and replace the line. If possible, see if you can do something like a non-greedy match (.*?) to match all the text between matches, and then replace it with a comma. (FYI: The ? operator is a non-greedy modifier in Perl-style regex engines. Other regex engines may not support this at all, or they may have a different syntax-- for example, Vim would use .\{-} for that.
|
|
|
|
|
Hello Community,
I have created Regex with Regex Magic with HTML 5 Firework, see attached.
The Regex [A-Za-z]{3}\d{4} successfully finds a string such as GMK6954 using Character Spaces.
Can someone help with modifying the Regex such that it replaces the first 3 letters with --- so the resulting Regex will generate the following
6954
Thanks
|
|
|
|
|
Change you digits to a "excluded suffix" and use String.prototype.replace() - JavaScript | MDN[^]:
[A-Za-z]{3}(?=\d{4})
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|