Given the name of an SQL table, I am looking to add quotes as necessary (with an loose definition of "necessary"). With SQL Server, the parts of the name should be wrapped in brackets ([ and ]), MySQL uses backticks (`). So, for example:
should all be transformed to:
What I have working; is capturing Wrapped and Unwrapped sections separately, wrapping the Unwrapped sections, and joining the sections back together. But it occurred to me that if I could Match only the Unwrapped sections, I could use Replace.
However, I have so far been unsuccessful in my attempts (otherwise I wouldn't be posting). Does anyone out there have an idea of how to do this? I'm thinking it may involve Balancing Groups, but I've never used them before so I'm finding them confusing.
This is not urgent.
Edit: I must have been over-thinking it . What I have now is (?<=^|\.)[^\[\]\.]+(?=$|\.)
The Regex sees a line like aaa bbb ccc . ddd . eee fff
What part of aaa bbb ccc is the database name? Only ccc or bbb ccc, etc.? You see the problem?
The same for eee fff.
Non-escaped/non-wrapped spaces in names is guess work to make them wrapped into [...].
I.e. to get from aaa bbb ccc .... to aaa [bbb ccc] .... is rather difficult, unless you know what aaa means or you say from outside that bbb ccc is a single name.
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.
Last Visit: 31-Dec-99 18:00 Last Update: 18-Aug-22 22:50