i aim to append prefix to each class name in my code. So i want class="text-black border-b p-2 border-gray-100 flex justify-between" to become class="tw-text-black tw-border-b tw-p-2 tw-border-gray-100 tw-flex tw-justify-between"
Try this find and replace:
Find: (?<=class="[^"]*)([^\s"]+)
Replace: tw-$1
See regex101 demo.
That uses a non-fixed length positive lookbehind (due to the * which can be any number) - so that regex will work in vscode's Find widget but not in the Search across files input. So only one file at a time.
Then the idea is to get all blocks that do not contain a space or " as a group $1.
Related
I'm deobfuscating some code and I forget the operator to use a wildcard while searching for text in VSCode. By this I mean in VSCode whenever you search for code (CMD/CTRL + F), what is the character for a wild card (i.e searching for "date{WILDCARD HERE}" would return "date1","date2","date", etc.)
I don't recall a wildcard option (I've never used it at least). But the search feature supports using regular expressions.
Given your examples of date1, date2, date, etc. assuming it followed a pattern of date<n> where n is a number (or nothing in the case of just "date"), the regular expression of date[1-9]* should achieve what you want.
You can test the expression out on this site. Input the regular expression and some sample data and see how it matches.
Using cmd+d to select the current word in VS Code also annoyingly selects any quotes that may surround the word. Is there any way to prevent this?
Edit: This appears to only happen in JSON files.
I can't reproduce the quotes selection with Cmd+D but I can with the Expand Selection command..
If you still have this issue. it may be fixed in vscode v1.69. The quotes will no longer be considered part of a json word. From the release notes:
Every language comes with a word pattern that defines which characters
belong to a word when in that language. JSON was different to all
other language in that it included the quotes of string literals and
the full string literal content. It now follows other languages and
contains just letters, numbers and hyphens.
The change will fix issues when expanding the selection (Command: Expand Selection), allow word completions inside strings and fix some
quick suggestion abnormalities.
I'm having trouble finding the proper Word wildcard string to find numbers that fit the following patterns:
"NN NN NN" or "NN NN NN.NN" (where N is any number 0-9)
The trouble is the first string is a subset of the second string. My goal is to find a single wildcard string that will capture both. Unfortunately, I need to use an operator that is zero or more occurrences for the ".NN" portion and that doesn't exist.
I'm having to do two searches, and I'm using the following patterns:
[0-9]{2}[^s ][0-9]{2}[^s ][0-9]{2}?[!0-9]
[0-9]{2}[^s ][0-9]{2}[^s ][0-9]{2}.[0-9]{2}
The problem is that first pattern (in bold). It works well unless I have the number in a table or something and there is nothing after it to match (or not match, if you will) the [!0-9].
You could use a single wildcard Find:
[0-9]{2}[^s ][0-9]{2}[^s ][0-9][0-9.]{1,4}
or:
[0-9]{2}[^s ][0-9]{2}[^s ][0-9][0-9.]{1;4}
to capture both. Which you use depends on your regional settings.
I want to search strings like "number 1" or "number 152" or "number 36985".
In all above strings "number " will be constant but digits will change and can have any length.
I tried Search option using wildcard but it doesn't seem to work.
basic regEx operators like + seem to not work.
I tried 'number*[1-9]*' and 'number*[1-9]+' but no luck.
This regular expression only selects upto one digit. e.g. If the string is 'number 12345' it only matches number 12345 (the part which is in bold).
Does anyone know how to do this?
Word doesn't use regular expressions in its search (Find) functionality. It has its own set of wildcard rules. These are very similar to RegEx, but not identical and not as powerful.
Using Word's wildcards, the search text below locates the examples given in the question. (Note that the semicolon separator in 1;100 may be soemthing else, depending on the list separator set in Windows (or on the Mac). My European locale uses a semicolon; the United States would use a comma, for example.
"number [0-9]{1;100}"
The 100 is an arbitrary number I chose for the maximum number of repeats of the search term just before it. Depending on how long you expect a number to be, this can be much smaller...
The logic of the search text is: number is a literal; the valid range of characters following the literal are 0 through 9; there may be one to one hundred of these characters - anything in that range is a match.
The only way RegEx can be used in Word is to extract a string and run the search on the string. But this dissociates the string from the document, meaning Word-specific content (formatting, fields, etc.) will be lost.
Try putting < and > on the ends of your search string to indicate the beginning and ending of the desired strings. This works for me: '<number [1-9]*>'. So does '<number [1-9]#>' which is probably what you want. Note that in Word wildcards the # is used where + is used in other RegEx systems.
I'm using regular expression lib icucore via RegKit on the iPhone to
replace a pattern in a large string.
The Pattern i'm looking for looks some thing like this
| hello world (P1)|
I'm matching this pattern with the following regular expression
\|((\w*|.| )+)\((\w\d+)\)\|
This transforms the input string into 3 groups when a match is found, of which group 1(string) and group 3(string in parentheses) are of interest to me.
I'm converting these formated strings into html links so the above would be transformed into
Hello world
My problem is the trailing space in the third group. Which when the link is highlighted and underlined, results with the line extending beyond the printed characters.
While i know i could extract all the matches and process them manually, using the search and replace feature of the icu lib is a much cleaner solution, and i would rather not do that as a result.
Many thanks as always
Would the following work as an alternate regular expression?
\|((\w*|.| )+)\s+\((\w\d+)\)\| Where inserting the extra \s+ pulls the space outside the 1st grouping.
Though, given your example & regex, I'm not sure why you don't just do:
\|(.+)\s+\((\w\d+)\)\|
Which will have the same effect. However, both your original regex and my simpler one would both fail, however on:
| hello world (P1)| and on the same line | howdy world (P1)|
where it would roll it up into 1 match.
\|\s*([\w ,.-]+)\s+\((\w\d+)\)\|
will put the trailing space(s) outside the capturing group. This will of course only work if there always is a space. Can you guarantee that?
If not, use
\|\s*([\w ,.-]+(?<!\s))\s*\((\w\d+)\)\|
This uses a lookbehind assertion to make sure the capturing group ends in a non-space character.