I was confused since I understood (say: assumed...) that you have an SQL script that you want to patch... Never assume anything
In that case your initial regex is probably the simplest solution.
So here I was, trying to figure out why I was having problems with my ASP RegEx validator control. The objective was to match to an IP address, but to allow it to end in "*" in the final octets (that is, 255.255.255.255 is valid, and so is 255.255.255.* or 255.255.*.* or 255.*.*.*).
But the validation was failing for 0.0.0.200, or anything over 199 in the last octet.
string b = @"25[0-5]|2[0-4]\d|1?\d?\d"; // longest match firststring n = @"(?:"+b+@")"; // wrap into non captuering groupstring w = @"(?:\*|"+b+@")"; // allow * and wrap into non captuering groupstring d = @"\."; // separating dotstring ip = n+d+w+d+w+d+w; // the whole ip = b.(*|b).(*|b).(*|b)
You generally need a modifier tacked on the end of the regex, or an extra parameter in the call to match or whatever to specify multiline input. I'm guessing your current call stops scanning at the first newline.
Sorry I can't be more specific without knowing what regex engine/language/context you're using.
Thanks for answering!
I tried to mess around NL settings, but without success. Could you get it working here: http://www.regexplanet.com/simple/index.html[^]? I'll be fine then (hopefully).
Ultimately, I want to use it in VS find/replace dialog (Notepad++ does not support NL in regex ).
I didn't look closely at the middle of your regex. Your fragment [\n.]* matches any number of (newline or fullstop) Inside the square brackets, the fullstop is not a wildcard. That is probably not what you want. A simple .* is probably what you need if you are not interested in capturing the content, given that the multiline flag should take care of "any character" matching newline.
Inside the square brackets, the fullstop is not a wildcard.
Oh, that was too easy
BUT, it would work if VS allowed to setup regex in a find/replace dialog. It is not possible though. However, the \n works. How to code that regex if . does not catch a new-line and it cannot be changed? (answer: code it yourself, but I would be nice if it wasn't necessary)
From what I can tell, that should be matching a SPACE that follows a anycharactersotherthanaquoteQUOTEanycharactersotherthanaquoteQUOTEanynumberofquotes, but you say it matches your test string so I must be misreading it.
At any rate, you can make something simpler. What exactly do you have and what do you want from it?
Thanks for all replies.
I'm trying to get words and if there are strings between quotes get that too that users have entered in a textbox. But I still don't understand how the string regexSplitter works. And I still don't understand why it has to be a space last in that string. Because when I remove it, it doesn't work as I want.
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*"; // maybe a more sophisticated pattern is// needed since the above expression seems// to match more,// but this is maybe an undesired side// effect of the complicated expression
string split = Regex.Matches(input, pattern).Cast<Match>().Select(m=>m.Groups.Value).ToArray();
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:
var to_index=manufacturer.lastIndexOf("_", manufacturer.length);
variable cleanUrl holds the url you are looking for.Hope this will help.
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):
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.
Last Visit: 31-Dec-99 19:00 Last Update: 31-Jan-23 17:20