|
How about: Order Date: \d\d\/\d\d\/\d\d
|
|
|
|
|
Perhaps with a couple of extra \d s to cope with the four-digit year?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oops again.
|
|
|
|
|
Hi Richard,
My string is like the following.
Order placed at the store. Order Date: 01/12/2017 10:54 AM This was completed.
I would like to pull "Order Date: 01/12/2017 10:54 AM"
Hope this helps.
Thanks,
Ana
|
|
|
|
|
If you take my original Order Date: \d\d\/\d\d\/\d\d , plus Richard Deeming's reply to me \d\d for the rest of the year, then you should be able to work out what else is needed. And you can test your expression online at RegExr: Learn, Build, & Test RegEx[^].
|
|
|
|
|
|
If you want to include the "Order Date: " in your extracted value:
Order Date:\s*[^\s]+
If you just want the "01/12/2017", and you're using C#, then:
(?<=Order Date:\s*)[^\s]+
(Other regular expression processors may also support "zero-width positive lookbehind" assertions. But Javascript, for example, doesn't.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Thanks for your response!
Since I need the order date, I tried using "Order Date:\s*[^\s]+" per your post above, and it is pulling text after the date, time and AM/PM. So, I would like to pull everything before the date, time and AM/PM.
Any suggestions would be appreciated.
Thank you!
Ana
|
|
|
|
|
So, my string is like the following.
Order placed at the store. Order Date: 01/12/2017 10:54 AM This was completed.
I would like to pull "Order Date: 01/12/2017 10:54 AM"
Hope this helps.
Thanks,
Ana
|
|
|
|
|
You specifically said you wanted to extract the text up to the first space, and there is a space between 2017 and 10:54 . And then another space between 10:54 and AM .
If the date and time is always in the same format - which doesn't match the example you gave in your original message - then try something like:
Order Date: \d\d\/\d\d\/\d\d\d\d \d\d:\d\d [AP]M Demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Sorry for the confusion. I tried the expression that you posted and it works perfectly!
Also, I would like to pull "Name is: Tia" from the following string:
My friend's Name is: Tia She lives in Argentina.
Thanks so much,
Ana
|
|
|
|
|
Only one name, with no spaces?
Name is: [^\s]+ Demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I tried "Name is: [^\s]+" but I am getting back the text after the space as well. How can I fix this?
Thanks,
Ana
|
|
|
|
|
You could try "Name is:\s([^\s]+).*$" .
The result will be in the first numbered group of the result.
string input = "My friend's Name is: Tia She lives in Argentina.";
Regex r = new Regex(@"Name is:\s([^\s]+).*$");
string name = r.Match(input).Groups[0].Value;
while (!(success = Try()));
|
|
|
|
|
Then there's either a bug with the regular expression engine you're using, or there's something wrong with your code.
[^\s]+ explicitly excludes any spaces. That pattern will match the first run of characters which are not spaces to appear after the prefix "Name is: ".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I'm using Notepad++ to do some Regex replacements and have come up against a problem I can't solve.
I'm looking to match a region between two fixed strings inclusive (called <startstring> and <endstring> for the sake of example). The problem I have is these strings appear multiple times throughout, but I want to match EACH instance, rather than one match from the very first <startstring> to the last <endstring>. They may or may not be over many lines. For example:
<startstring>
...text body...
<endstring>
...other text...
<startstring>
...text body...
<endstring>
...other text...
<startstring>
...text body...
<endstring>
I need my Regex to make 3 separate matches, rather than 1 big match which includes all the ..other text... which I need to be left intact.
The above needs to work irrespective of whether the <startstring> and <endstring> are on the same line or many lines apart.
Thanks in advance.
|
|
|
|
|
Try:
public static Regex regex = new Regex(
"\\<startstring\\>.*?\\<endstring\\>",
RegexOptions.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
...
MatchCollection ms = regex.Matches(InputText);
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks, that's led me to the correct solution for all eventualities
|
|
|
|
|
You're welcome!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello, I am new to using Regex and hope someone can help with my expresion.
I am using VB.net Regex.Match() to extract info.
I cannot figure out how to include the text at the end of a line in my expression.
I'm using Expresso for testing my expression.
Expression without double quotes:
"(.*?)(\\~zs\\~ls)(.*?)(\\~le\\~ks)(.*?)(\\~ke\\~hs)(.*?)(\\~he\\~ze)(.*?)"
Source Data1:
test \~zs\~lsMt+22:21\~le\~ksMt+22:211\~ke\~hs\~he\~ze end of line
Returns:
[test \~zs\~lsMt+22:21\~le\~ksMt+22:211\~ke\~hs\~he\~ze]
1: [test ]
2: [\~zs\~ls]
3: [Mt+22:21]
4: [\~le\~ks]
5: [Mt+22:211]
6: [\~ke\~hs]
7: []
8: [\~he\~ze]
9: []
I do not get a reference to [end of line]
Source Data2:
\~zs\~lsMark+1:1\~le\~ksMark+1:11\~ke\~hs\~he\~ze some data \~zs\~lsMark+2:1\~le\~ksMark+2:11\~ke\~hs\~he\~ze end of line
Returns 2 matches:
Match1:
[\~zs\~lsMark+1:1\~le\~ksMark+1:11\~ke\~hs\~he\~ze]
1: []
2: [\~zs\~ls]
3: [Mark+1:1]
4: [\~le\~ks]
5: [Mark+1:11]
6: [\~ke\~hs]
7: []
8: [\~he\~ze]
9: []
Match2:
[ some data \~zs\~lsMark+2:1\~le\~ksMark+2:11\~ke\~hs\~he\~ze]
1: [ some data ]
2: [\~zs\~ls]
3: [Mark+2:1]
4: [\~le\~ks]
5: [Mark+2:11]
6: [\~ke\~hs]
7: []
8: [\~he\~ze]
9: []
Again, I do not get a reference to [end of line]
I've tried end the expression with this (.*$) which works for Source Data 1 but
Source data 2 just returns one match with 9:[ some data \~zs....]
Can someone help me with extracting the [end of line] text to item 9:?
thank you
|
|
|
|
|
I'm not a Reg Exp expert, but I recall that '.' matches anything EXCEPT newline so try replacing (.*$) with ((.|\n)*$) . You may also need to switch on multiline matching
|
|
|
|
|
Hi, we are having troubles whit checking a textfield. What we try to do here is to check if the default text has changed. If that is not the case, then a warning will appear at the end of the form.
Everything is working fine until a textfield contains a 'return' (enter) in the text. Even when the default text is gone, the enter will be responsible for the regex-code to fail..
Here the code i have used:
^((?!\bThis contains the default text).)*$
Pleas let me know if you can help me out here
What I have tried:
several codes... Sorry, i don't have them anymore. We also checked the code with a validator.
|
|
|
|
|
You can use (c#) .Trim() on a string to remove leading / trailing "white space", carriage returns, etc.
I tend to do that automatically any time I "save" a string (in a database, for example).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It sounds like you need to add an option your regular expression to work "multiline"? Have you got some code you can show us?
Have a look at https://regexr.com/3maco
Now is it bad enough that you let somebody else kick your butts without you trying to do it to each other? Now if we're all talking about the same man, and I think we are... it appears he's got a rather growing collection of our bikes.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
The code i have used is in niet question. IT is no longer
|
|
|
|