We help IT Professionals succeed at work.

Regex Pattern

TheCommunicator
TheCommunicator used Ask the Experts™
on
Hello everybody,

Well, basically I am lookin for a Regex pattern that helps me find and replace following pattern

lookupKey="AR Contains AR"

So I have this LookUpKey attribute in my XML document and what some of the attribue values have spaces inside and what I want is something whcih finds these spaces and replaces them with "-"( A hyphen)

How can I come up with that kind of combincation?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Guru
Most Valuable Expert 2011
Commented:
Try:

Find:
(?<=lookupKey="")([^"" ]*)\s

Replace with:
$1-

Author

Commented:
Well, that did not work but someboyd already did it for every look up attribute and that looked something like

{lookupkey="}[a-z\- ]*"

Now, we have to actually narrow it down to all the look up attributes with spaces inside the values.

???
Terry WoodsIT Guru
Most Valuable Expert 2011
Commented:
Can you get the exact code?

If there's any issue with the above, it will just be the escaping I believe - the backslash should probably be escaped, and I think in C# you need to use the @ character before the string (unless you use extra escaping):
@"(lookupKey=""[^"" ]*)\\s"
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Are you trying to find this in code, or in the Visual Studio editor itself (i.e. the Find/Replace dialog)?

Author

Commented:
Yes I am trying to find this in visual studio editor.
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Try this:

lookupKey:b*=:b*"[^"]*"

Open in new window


and if you're trying to capture part of it, as it looks like in your earlier example, then try:

{lookupKey:b*=:b*"}[^"]*"

Open in new window

kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
If you might have quotes inside your string, then you should be able to use this:
lookupKey:b*=:b*"(\\"|[^"])*"

Open in new window

Author

Commented:
This helped thanks:)