Regex Search With Quotations
-
I am trying to search a folder (20-30 text files) for a string that can contain a variety of letters in the alphabet.
example 1:
range(“A1”)
search = "Aexample 2:
range(“$I$15:$I$19”)
search = "$A and $Inow I want to do this for all letters so I thought it would be something to the affect of for…
ex 1: A|B|C|D|E|F|G|H|I|JK|L|
ex 2: “$A|”$B|“$C|”$D|“$E|”$F|“$G|”$H|“$I|”$J"$K|"$L|neither work.
thanks in advance. any assistance is appreciated.thanks!
-
@devsrc8 ,
For
|
to work as logical-OR, you have to be in Regular Expression mode. But in regex mode,$
means “end of line”, not a literal dollar sign.Regex have prebuilt character classes which will help with your search; in your case,
\u
will search for an upper-case letter. So"\u
will match every time there’s a quote followed by an upper case.To search for a literal dollar sign, you need to escape with
\
it so it will be treated as a literal character:\$
. So\$\u
will match any uppercase letter that comes after a literal dollar sign.----
Please note that your examples sometimes had"
and sometimes had“
– those are two different characters. If you had followed the advice given in “Please Read Before Posting” (which you should have seen immediately below the New Topic button that you clicked):
and the advice it links to in the “Template for Search/Replace Questions” and “Forum Formatting Posts” FAQ entries, you would have been instructed how to present your question in a way that left no ambiguity as to which was the “right” quote characters for your data. -
@peterjones thanks for the quick reply!
as well as guiding me towards very helpful artifacts that I should have reviewed.
how do you make $\u and "\u only pull UPPER case instances?
I will read in more depth, but simply searching for \u in an effort to locate how to only pull UPPER case letters I don’t yielded the correct information.
section:
Then use the following regex S/R :
Search for: (?-i)[\u\d]\K\x20(?=[\u\d]) -
how do you make $\u and "\u only pull UPPER case instances?
\u
only matches uppercase, unless you have case-insensitive match turned on. (If case insensitive is on, obviously uppercase and lowercase will both match, by definition of case insensitive)I don’t yielded the correct information.
Well, you haven’t given any example data that doesn’t match your expression. That makes it harder to help you. That’s why I pointed you to those posts, because they explain the importance of providing sample data that actually matches the data that you have.
(?-i)[\u\d]\K\x20(?=[\u\d])
That’s a very different expression than I gave you, or than what was necessary to match text in your screenshot. That is saying “turn off case-insensitive-match; there must be an uppercase or digit, then reset the match, then find a space that is followed by uppercase or digit”. That has nothing to do with the example data you showed above.
But given the description I just made, the expression you listed matched everything I expected in my example text below:
range("A1") range("$I$15:$I$19") lowercase lowercase UPPER UPPER 314 159 UPPER lowercase lower UPPER 314 lower 314 UPPER lower 159 UPPER 159
It matches the spaces that come between two UPPER, or the spaces between two DIGITS, or the spaces between a digit and an upper in either order. That’s exactly what I would expect.
-
-
@devsrc8 ,
So your screenshots show exactly what I would expect. With match case on,
\u
only matches uppercase. With match case off,\u
matches either uppercase, or, because it is ignoring case, lowercase as well. That’s how things are defined to work.If you want to have case-sensitive
\u
no matter what, use(?-i:\u)
to make the parenthesized subgroup case sensitive no matter what the checkbox says:
-
@peterjones thanks for all your help!
is there a marked as Solved for this forum?