|
Could you help me write a pattern for Regex.
I need to look for file name with this pattern:
string(no number; only 100 characters)-6digitnumber_string
|
|
|
|
|
what have you done so far?
and can you clarify with some positive and negative examples?
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.
|
|
|
|
|
Off the top of my head, this one should suffice:
([a-zA-z]{100}\d{6}[a-zA-Z]{1,})
|
|
|
|
|
examples:
Testing-123456_filename.xls - valid
My-1234568_filename.txt- not valid (because 7 digits)
Testring-123456-filename.dat- not valid( missing _)
filename.txt - not valid( missing _ and - )
Testring_123456_filename.dat- not valid( missing -)
|
|
|
|
|
This doesn't match what you specified originally. You stated that it should be 100 characters, but My-, for instance, isn't. So, which set of rules are correct?
|
|
|
|
|
clarification:it can be up to 100 charachers
|
|
|
|
|
Then try this:
[a-zA-Z]{1,100}-\d{6}_[a-zA-Z]{1,}
|
|
|
|
|
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.
|
|
|
|