|
WORKING!!!!!!!!!! THANK YOU
|
|
|
|
|
-\d{6}_
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
If I used you pattern I am getting all invalid returns
Here my code and test cases:
Public Function Verify(ByVal myFileName As String)<br />
Dim Pattern As String = "-d{6}_"<br />
'"([a-zA-z]{100}\d{6}[a-zA-z]{1,})"<br />
Dim MyRegex As New RegularExpressions.Regex(Pattern, RegularExpressions.RegexOptions.IgnoreCase)<br />
Return MyRegex.IsMatch(myFileName, 0)<br />
End Function
Testing scenario:
If Verify("Granic-012345_Test-Granic.txt") Then ' should be valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("TESTTING-123456-Norman_NDtest1.dat") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("GRANIC-123456_jayson.xls") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("incoming-testfile.txt") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
<br />
If Verify("Testing-474948_filename.txt") Then ' should be valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If
|
|
|
|
|
that is a useless message: a lot of code, but no results.
and code should be in PRE tags, not CODE tags.
it would help if you would copy my suggestion correctly.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
but if he kept the \ then there would be compile time errors, so it is best to just not put it in than to work out why it causes an issue, right?
I may or may not be responsible for my own actions
|
|
|
|
|
Wrong.
if it is to be a string literal (not stated explicitly), then it would be OK in some languages such as VB.NET (not specified), it would not be OK in some others such as C, and it would be OK in C# only when using a preceeding @ sign or doubling the \.
And that is exactly why I didn't put any double quotes at all, I only specified what the content of the string had to be. I trust people know their programming language of choice well enough to turn that into a string literal if that is what they need.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Now how did I know VB was going to come back and bite me on the ass for that one
I may or may not be responsible for my own actions
|
|
|
|
|
It would be better for us if you could come up with some examples ?
As I understood from your given information, this is required to you:
^\D{5}\-\d{6}_\D{1,}$
So it should match with this kind of samples:
aaaaa-666666_a
|
|
|
|
|
Dear experts,
I want to write a Regex in DataAnnotations that can unmatch a input string containing not paired double quote "
ie. check if zero or a paired double quote allowed in a input string. pls kindly advise. thx
matched case:
abcde
"abcde"
abc"d"e
unmatched case:
"abc"de"
"abcde
abc"de
abcde"
MY EXISTING CODE FYR:
...
using System.ComponentModel.DataAnnotations;
using Microsoft.Web.DynamicData;
...
namespace EDMModel
{
[MetadataType(typeof(DETAIL_MetaData)), ScaffoldTable(true)]
public partial class DETAIL{}
public class DETAIL_MetaData
{
[Required, RegularExpression(@"[^~`!@#%&()={}|:;'<>,./+?*^$]*", ErrorMessage = "Unsupported Character detected"), StringLength(20), Display(Order = 21)]
public object NAME1 { get; set; }
...
....
|
|
|
|
|
Not exactly sure how it is in DataAnnotations, but the regexp would be:
^[^"]*("[^"]*")*[^"]*$
If you have further character limitations, you could put them in instead of just [^"]
|
|
|
|
|
I'd like to extract data from blogspot feed. I've used regex only for Rainmeter, so this is what I came up with:
(?siU)</id><published>(.*)</published><updated>.*</updated><title type='text'>(.*)</title>.*<link rel='alternate' type='text/html' href='(.*)'
I assume the "(?siU)" part is wrong. What would be the correct format?
I've also heard about php's xml_parser, but I think regex is faster. Still, how would I extract same data as in above (broken) regex with xml_parser in php?
Thanks in advance!
|
|
|
|
|
You should be a little more clear about exactly what you are trying to do with that question mark, but here are some things to keep in mind...
If you have well formed XML, an XML parser is almost certainly the way to go. It might actually be faster than a regular expression. Unfortunately, I'm not familiar with PHP's XML parser, but you should take the time to familarize yourself with it.
Also, the question mark means "the preceding item is optional". Since the question mark is after an opening paren, there is nothing preceeding it, so I'm not exactly sure what you're after there. Depending on the regular expression engine you use, you can use a similar syntax for positive and negative lookaheads and lookbehinds, and you can use them for named groups. Or if you put a backslash to the left of the question mark, you'll escape it so it matches a literal question mark. But I'm not really sure what you're trying to do here. For example, if you were trying to get the query string value out of a URL, you could use a named group to grab it:
http://www\.google\.com\?(?<QUERY_STRING>.*)
Notice I use the question mark twice. The first time as a literal question mark and the second time as part of a named group. Here is another example:
http://www\.google\.com(?=\?)
That is a positive lookahead that ensures the character following the "m" is a question mark. But it doesn't actually grab the question mark as part of the pattern, it only ensures that the URL will match if that question mark exists in the right location. And of course, there is this use of the question mark:
http://www\.google\.com\??
That means the last question mark is optional. And then there is one more use of question marks (lazy matching rather than greedy matching) that goes like this:
\<img\>.*?\</img\>
I'll leave it up to you to figure out what that does if you are interested. One more thing, the less than and greater than signs have a special meaning in regular expressions. You may want to escape them by putting a backslash to the left of them.
|
|
|
|
|
|
Hi,
I'm not very good at RegEx , I want to use RegEx class to match values with desired string. My main string looks like this:
<%#String.Concat ..blah blah.. %>
in above string I want to get all the matches which between double quotes ( " ... " ) in blah blah part.
What is my expression should look like?
Thanks for your help
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
you should post in no more than one location (a single forum, or Q&A) so everything about this topic stays together.
|
|
|
|
|
It's not the best in the world, but it does the job:
public static Regex regex = new Regex(
"<%[^\\\"]*\"(?<InQuotes>.*)(?=\\\")[^%]*%>",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
public static string regexReplace =
"<Hello>";
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
hi guys
i wanna a pattern to find number of html control in whole page
i test this pattern but thers no result:
@"\b((<\s*"+pattern+@"{1})\s(\s*\w*\s*\W*\s*\d*\s*)*/>\b)"
that pattern is a variable that contain like img,input and so on
|
|
|
|
|
Perhaps show examples of the HTML and pattern.
|
|
|
|
|
I'm not in the least bit supprised it doesn't work as you expected. It isn't a valid regex.
Go to www.ultraPico.com[^] and D/L a copy of Expresso - it examines, designs and explains regexes. It's free, and I use it a lot. I really wish I'd written it!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: It isn't a valid regex.
Works fine for me. Doesn't produce the expected results, but it will compile and it does return results under certain scenarios.
|
|
|
|
|
Take out both occurrences of "\b".
moein.serpico wrote: {1}
That is completely useless.
moein.serpico wrote: (\s*\w*\s*\W*\s*\d*\s*)*
And what is all that for?
|
|
|
|
|
You could have my TIP[^] to be useful.
|
|
|
|
|
Guys,
Seems quiet around here, but hey-ho...hopefully I'll get a response.
OK - I have the following Regex:
^https?://([a-zA-Z0-9-_]*[/\.]{1})*([a-zA-Z]^\.)*(aspx)?
Which I've created using an online regex builder[^]
It's intended to match urls on either www. or local network, with or without a page (.aspx) on the end (so either www.site.com/ or www.site.com/page.aspx). The problem I have is that for all cases it seems to work correctly, until I drop it into my C# / Silverlight app (with the 2 x \ escaped as \\).
The problem is that under the regex builder, a .aspx is fine, a .aspxs is flagged as not matching - which is exactly what I need...however, in c# the aspxs is not flagged as invalid.
I think I can see why - because the s is part of the group, it's permitted - so I'm trying to essentially do an Optional literal string...the ? to make it optional, the brackets to apply to the group...but c# seems to be percieving it more as [aspx]* . If I remove the bracket, then the ? only then applies to the x on the end (as with the s in https at the start)...
Any ideas what I've missed here?
C# has already designed away most of the tedium of C++.
modified on Friday, August 6, 2010 6:33 AM
|
|
|
|
|
A shot in the dark. Try $ (matches end-of-string) at the end of your regex. Maybe one environment assumes it, the other not.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
By jove I think he's got it!
Good work fella...thanks a lot!
C# has already designed away most of the tedium of C++.
|
|
|
|