|
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!
|
|
|
|
|
Hi Griff,
Thanks for reaching out. Unfortunately, it didn't work.
The replacement just returns
[A-Za-z]{3}(?=\d{4})
|
|
|
|
|
And how - exactly - did you try it?
"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!
|
|
|
|
|
Is it possible to send an attachment on this forum
I would like to send a screenshot to you.
|
|
|
|
|
No. Copy'n'paste the relevant code fragments.
"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!
|
|
|
|
|
Hi, sorry for the delayed response.
I wanted to show you a screenshot, because I'm not getting an error from the application I'm using. It's replacing the string with [A-Za-z]{3}(?=\d{4})
Let me know if you can see the screenshot from the link below?
regmagic2.png - Google Drive[^]
|
|
|
|
|
And what do you think that tells me about how you coded it?
To quote myself:
Quote: And how - exactly - did you try it?
If you go for a drive and break down, when you call the garage, do you send them a picture of the view you can see out the car window? Or tell them what happened and where you are?
"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!
|
|
|
|
|
I dont understand.
Did you see the screenshot?
I simply cut-and-paste your regex
I should point out the regex I originally sent was not generated by me - I simply got the regex using an application called RegexMagic.
I am 100% new to Regex.
This means, I really don't have a clue what you're referring to.
Please help
|
|
|
|
|
Code.
A regex doesn't exist in isolation - it has to be used in code in order to do anything. On it's own, it's just a string ...
"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!
|
|
|
|
|
What does it take to get you to copy and paste the code you're using where you're setting up and using this RegEx?
|
|
|
|
|
Hi Dave,
Sorry for the delayed response
The reason for wanting to show a screenshot is because I use application to insert the a Search and Replace regex. So I would enter [A-Za-z]{3}\d{4} in the Search dialogue box, and [A-Za-z]{3}(?=\d{4}) in the replace dialoge box.
The search regex works fine, but the replace regex returns [A-Za-z]{3}(?=\d{4})
I'm assuming the the Regex pattern HTML 5 FireFox doesn't allow for replace?
|
|
|
|
|
You're making a lot of baseless assumptions and STILL not providing what is needed to solve the problem.
|
|
|
|
|
Dave,
I'm not sure I could be any clearer.
If you looked at the image you would see exactly what happens when I insert the Regex
|
|
|
|
|
Never heard of DataCleaner. Don't use it and not going to start.
If it's some tool you found somewhere, your best source of support is going to be whoever wrote it.
Your BIGGEST mistake was never telling anyone you were using some tool to do this work instead of writing your own code to do it.
|
|
|
|
|
Hi Community,
I have come to the conclusion that it may not to be possible to change the case of a string in JAVA 8 as simply as it is to change the case in say Perl.
However, before I move on, I just wanted to have someone on this forum confirm its not possible to change the case in JAVA 8 as follows:
Insert the whole regex match or the 1st through 99th backreference with the first letter of each word in the matched text converted to uppercase and the remaining letters converted to lowercase.
Example
Replacing .+ with \I0 in HeLlO WoRlD yields Hello World
Can someone confirm that the above isn't possible with JAVA 8?
If its not possible, can someone let me know how to achieve the above with JAVA 8?
Thanks
|
|
|
|
|
I suggested to you last week that it would be easier to use string functions to do what you want. Convert the entire string to lower case, then find each word beginning and convert the single letter to upper case.
|
|
|
|
|
Hey Richard,
I was so fixated with the way I wanted to achieve the result that I didn't realise how easy it is to get the result using your suggestion. TBH, with your suggestion I can get the result just using SQL, converting the entire string to lower case (as you suggested) and using a simple SQL function (which I'm familiar with) to Capitalize each word.
I literally would have saved myself 9 hours of trying to figure this out.
Thanks man
|
|
|
|
|