I have a large quantity of data in the following format:-
EXPERTISE_JOBTITLECOOKIE = "JobTitleCookie";
EXPERTISE_POSITIONCOOKIE = "PositionCookie";
EXPERTISE_QUALIFICATIONSPROFESSIONALMEMBERSHIPSCOOKIE = "QualificationsProfessionalMembershipsCookie";
EXPERTISE_YEARSOFEXPERIENCECOOKIE = "YearsOfExperienceCookie";
EXPERTISE_ADDITIONALCOMMENTSCOOKIE = "AdditionalCommentsCookie";
I'm looking for some regex that could be used to replace all characters after the =
characters, to leave only the variable name in capitals.
I tried:
^\*\d+$
but this isn't picked up. I'm also looking for regex for the same problem that works in Sublime Text 2.
Could someone explain what the above does, and what I might be looking for in a RegEx statement?
Thanks
Select the list you will replace all after/before the specific characters, and press the Ctrl + H keys simultaneously to open the Find and Replace dialog box. Note: You can also open the Find and Replace dialog box by clicking Home > Find & Select > Replace.
In regex, the uppercase metacharacter is always the inverse of the lowercase counterpart. \d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ).
Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol. Example: "^a" matches "a" at the start of the string.
Regex Replace We can also call the string replace method with a regex to remove the part of the string after a given character. The /\?. */ regex matches everything from the question to the end of the string. Since we passed in an empty string as the 2nd argument, all of that will be replaced by an empty string.
Could someone explain what the
^\*\d+$
does
^
- Anchor that indicates the start of the line\*
- The *
character literally (since it's escaped)\d+
- One or more digits [0-9]
$
- Anchor that indicates the end of the lineIn other words, ^\*\d+$
will match a line such as *1
or *10000
.
You are looking for a regular expression to capture the characters until the =
character:
^(.*?) =.*$
This will capture the characters before a space followed by the =
character, and the match all of the remaining characters on that line so that they can be replaced.
If you want to remove everything after the capturing group, just replace with \1
as demonstrated by this example here.
If you want to modify the string after the =
character, replace with \1 = "Some String"
, as demonstrated by this example here.
I'd do:
Type Ctrl+H
Find what: =.+$
Replace with: NOTHING
Type Replace all
Be sure you have checked Regular Expression
but NOT . matches newline
.
This will replace everything after =
(included) by nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With