|
There has to be something. Have you tried other characters?
|
|
|
|
|
Hi
What do you meen by something? I can write any characters I want in a word or a string. For example the text can contain
'hello by "to much" 10'.
Thanks
Fia
|
|
|
|
|
I mean the SPACE (or something else) needs to be there.
|
|
|
|
|
See my explanation below (I know, this is very old topic, but I see it was not solved in this thread, so I added my lengthly explanation below).
The Regex matches for spaces where the prefix expression ((?<=...) ) matches.
Far too complicated for cases where one wants to have a string split into part separated by spaces, ignoring spaces within "...".
My preferred solution is using positive match criterion (as described in the sentence above):
string pattern = @"\s*(""[^""]*""|\S+)\s*";
var fields = Regex.Matches(input, pattern).Cast<Match>().Select(m=>m.Groups[1].Value);
Cheers
Andi
|
|
|
|
|
See The 30 Minute Regex Tutorial and search for all occurances of (?<= in that article. This explains the meaning of (?<=...) .
You have always to separate the way you enter a pattern in C# and the pattern the Regex sees:
C# @"..." pattern: | @"(?<=^(?:[^""]*""[^""]*"")*[^""]*) " | effective Regex pattern (here delimited by /.../): | /(?<=^(?:[^"]*"[^"]*")*[^"]*) / |
I'm now only talking in Regex domain (the 2nd row), not how it is entered in the C# string.
Let's start with the inner most part and work outwards:
..."[^"]*"... : "..."...[^"]*"[^"]*"... : any number of non-"-char, followed by "..." from 1. above...(?:[^"]*"[^"]*")*... : any repetition of the group described in 2. above...^(?:...)*... : 3. above must match from the beginning of the text...^(?:...)*[^"]*... : 4. above, followed by any number of non-"-char(?<=...) : match a space that is preceeded by the expression from 5. above; the (?<=...) is not part of the match
The Regex searches for the space character and checks if the data before that space matches the prefix expression. If yes, the match is successful, otherwise, the Regex searches for the next space and checks again, etc.
The given Regex and the given data match only on one space, the one after all . The underlined part matches with all : (?<=^(?:[^"]*"[^"]*")*[^"]*) .
I.e. the regex splits the given data by spaces, respecting spaces within "..." strings as non-separators.
Very complicated, though. I would do this differently, namely in positive terms (what you want to be part of the fields rather than what splits them):
string pattern = @"\s*(""[^""]*""|\S+)\s*";
string[] split = Regex.Matches(input, pattern).Cast<Match>().Select(m=>m.Groups[1].Value).ToArray();
Cheers
Andi
modified 8-Apr-12 7:03am.
|
|
|
|
|
Hello there,
I need some clever regular expression writing in IIS7 to redirect traffic from one site to another, the pages are similar in structure but information needs re-writing.
Here's an example:
http://www.mysite.com/manufacturers/Name_of_Manufacturer_6828/Name_OF_Product_43146.htm
needs to be structured as the following
http://www.newsite.co.in/free-msds-download/name-of-manufacturer/name-of-product/
Here's what needs changing:
1). Only Alpha, Numeric and hyphen's allowed.
2). Change '_' to '-'.
3). Remove the '_NUMBER' directly after the manufacturer name and before the '/'.
4). Remove the '_NUMBER' directly after the product name and before the '.htm'.
5). Remove the '.htm' and replace with a '/'.
It needs writing into the code below please as a permanent 301 redirect:
|
|
|
|
|
Hi,
You can use the JavaScript below,
var str="http://www.mysite.com/manufacturers/Name_of_Manufacturer_6828/Name_OF_Product_43146.htm";
str=str.replace("http://www.mysite.com/manufacturers/", "");
var key=str.split("/");
var manufacturer=key[0];
var product=key[1];
var to_index=manufacturer.lastIndexOf("_", manufacturer.length);
manufacturer=manufacturer.substring(0, to_index);
manufacturer=manufacturer.replace(/_/gi, "-");
product=product.replace(/.htm/gi, "");
to_index=product.lastIndexOf("_", product.length);
product=product.substring(0, to_index);
product=product.replace(/_/gi, "-");
var cleanUrl="http://www.newsite.co.in/free-msds-download/"+manufacturer+"/"+product+"/";
document.write(cleanUrl);
variable cleanUrl holds the url you are looking for.Hope this will help.
|
|
|
|
|
I am going to make a few assumptions. Since you said this is in IIS, you probably can't create .Net or JavaScript code to handle the redirect (i.e., all redirects must be done using some regexes in a configuration file). Also, I assume the number of underscores in the "mysite.com" URL is variable.
I don't think you can do this with one redirect, but you can create several. For example, you can start off with these (create more to handle more underscores):
^http://www\.mysite\.com/manufacturers/(?<MAN>[a-z0-9]+)_[0-9]+/(?<PRO>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN}/${PRO}/
^http://www\.mysite\.com/manufacturers/(?<MAN1>[a-z0-9]+)_(?<MAN2>[a-z0-9]+)_[0-9]+/(?<PRO>[a-z0-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN1}-${MAN2}/${PRO}/
^http://www\.mysite\.com/manufacturers/(?<MAN>[a-z0-9]+)_[0-9]+/(?<PRO1>[a-z9-9]+)_(?<PRO2>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN}/${PRO1}-${PRO2}/
^http://www\.mysite\.com/manufacturers/(?<MAN1>[a-z0-9]+)_(?<MAN1>[a-z0-9]+)_[0-9]+/(?<PRO1>[a-z9-9]+)_(?<PRO2>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN1}-${MAN2}/${PRO1}-${PRO2}/
That is simple enough, but that could end up being a lot of rules if you have a large range of underscores (e.g., "the_name_of_some_long_product" and "the_name_of_some_long_manufacturer"). Alternatively, you can redirect all of the "mysite" URL's that match the pattern you want to a single URL on "newsite" that takes the original URL as a query string. The page on newsite can then parse the query string and perform a redirect using C# or VB.Net code, which gives you more flexibility than a configuration file.
Note: the above regexes are untested and may contain mistakes, but you get the idea.
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
I need to check whether password has at least 6 characters with at least 1 letter and one special character. I am checking the condition !Regex.IsMatch(strPassword,"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,24})$"). But it doesnot allow special character.
I need to change the expression to check if there is at least one special character.
Please help me out.
|
|
|
|
|
^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{6,}$
- ^ checks for the start of the input string.
- (?=.*[a-zA-Z]) checks that there are at least one letter.
- (?=.*[0-9]) checks that there are at least one digit.
- (?=.*[^a-zA-Z0-9]) checks that there are at least one special character (not a letter nor digit).
- .{6,} checks that there are at least 6 characters.
- $ checks for the end if the input string.
See also
|
|
|
|
|
I need help with regular expression for a javascript I'm working on.
I have some html code into a variable that is named xmlDoc. The string includes a table and there are some things there that I want to pick out with regex.
<tr class="myGreyRow">
<td>6</td>
<td id="fn1">Prentice, Bob</td>
<td>340584305858</td>
<td>Logged out</td>
<td>
<a class="listlink" href="javascript:doEditAgent("56746")">Edit</a>,
<a class="listlink" href="javascript:doRemoveAgent("56746", "fn1")">Delete</a>,
<a class="listlink" href="javascript:doLoginLogout("4", "56746","fn1")">Log in</a>
</td>
</tr>
In this code I want to pick out:
1. The name, "Prentice, Bob"
2. The status, "Logged out"
3. The content from doLoginLogout(), "4", "56746","fn1"
What pattern(s) should I use?
There are five rows similar to this in the table that I need to do this on.
|
|
|
|
|
|
Hi Everyone,
I am trying to figure out how to parse html line and take from it the $ sign and a the monetary value.
For example:
The price of the book is $15.00 and the price of the computer is $1,299.99 cents.
Thank you.
|
|
|
|
|
\$(\d{1,3}(,\d{3})*)(\.\d\d)?
modified on Wednesday, September 7, 2011 10:24 AM
|
|
|
|
|
Thanks for the reply. I doesn't seem to work.
Can you explain briefly what you are attempting to match with that expression?
Thank you.
|
|
|
|
|
It does work. Try this in a console app:
static void Main(string[] args)
{
Regex rx = new Regex(@"\$(\d{1,3}(,\d{3})*)(\.\d\d)?");
foreach (Match m in rx.Matches("This matches $4.12 dollars. It also matches $32.32 or $15 or $2.11 or $0.12 or $156,789.33 or $12,345.67"))
{
Console.WriteLine(m.Value);
}
Console.ReadKey();
}
Output:
$4.12
$32.32
$15
$2.11
$0.12
$156,789.33
$12,345.67
Of course, you must reference the System.Text.RegularExpressions namespace. Also, here is a page you can use to help learn regular expression syntax:
http://www.regular-expressions.info/reference.html
|
|
|
|
|
Thank you for the sample and the link. It works.
|
|
|
|
|
I ran that Regex against your test case and it works perfectly. What output are you getting? What does your code look like that's calling it?
|
|
|
|
|
Member 8216828 wrote: I am trying to figure out how to parse html line and take from it the $ sign and a the monetary value.
In general it isn't a good idea to parse html/xml via regular expressions.
Instead one should use a html/xml parser.
One might use regex if all of the following is true.
1. The source(s) for html/xml are limited. Thus for example there is only one source and there is unlikely to be another.
2. The source is machine generated (thus a library was used to create it rather than an adhoc code of some sort.)
The reason this isn't a good idea is because there are many variations in the way html/xml can be formatted. By the time one has accounted for all of those variances either one has a parser or one has a maintenance problem (or maintenance nightmare).
|
|
|
|
|
Hi Guys,
I have three Regex and would like to know if it's possible to combine them into one.
I'm validating phone numbers in the form:
- 0219081234
- 021 908 1234
- 021-908-1234
here are my regex for the above in order:
- var phoneRegex1 = /^(\d{3})(\d{3})(\d{4})$/;
- var phoneRegex2 = /^(\d{3})(\-)(\d{3})(\-)(\d{4})$/;
- var phoneRegex3 = /^(\d{3})(\ )(\d{3})(\ )(\d{4})$/;
Thanks in Advance,
Morgs
|
|
|
|
|
Just use ? operator
Like this:
^\d{3}-?\s?\d{3}-?\s?\d{4}$
You can flame me whichever way you want and I wouldn't care a bit.
But if you group me with some idiots, I'll turn into your worst nightmare.
|
|
|
|
|
Thanks a ton Firo,
will give it a try...
Morgs
|
|
|
|
|
I think that would match values like:
123456-7890
123456 7890
123456- 7890
123-4567890
123-456 7890
123-456- 7890
123 4567890
123 456-7890
123 456- 7890
123- 4567890
123- 456-7890
123- 456 7890
123- 456- 7890
Which are not in his spec.
|
|
|
|
|
If you want to ensure that the separators (if any) between the groups are the same, I think you need to use a backreference[^].
Something like this perhaps:
(?'Area'\d{3})(?(?=(\s|-))(?'Sep'(\s|-)))(?'Prefix'\d{3})(?(Sep)\k<Sep>)(?'Number'\d{4})
modified on Sunday, July 17, 2011 2:00 PM
|
|
|
|
|
I think this is what you need.
^\d{3}(-|\s)?\d{3}(-|\s)?\d{4}$
|
|
|
|