![]() ' 3.14159' matches ' the quick brown fox' does not match. result=STRMATCH(string, 'Ll+') result=STRMATCH(string, '^.*x$') Matches any string containing a period. result=STRMATCH(string, '^at') Matches any string containing ' L' followed by one or more occur rences of ' l': ' Get a Llama' matches ' larry the llama' does not match (first l in llama is lower case). ![]() result=STRMATCH(string, 'a') Matches any string beginning ( ^) with Cat, bat, and so on: ' Cat Woman', ' catatonic', ' Batman, the animated series' but does not match: ' cat' (begins with a space), ' cab', and so on. Matches any string containing the character ' a'. The following PV‑WAVE commands demonstrate the regular expression pattern matching used in the STRMATCH command. /g: This enables our command to work globally on each line.Assume that string is a string array defined in PV‑WAVE.The numbers have to be preceded by a backslash ( \). Because we want to reverse the order, we type them as second-match,first-match. \2,\1 /g': Because we enclosed our two subexpressions in parentheses, we can refer to both of them by their numbers.The forward slash ( /) completes the search pattern section. We don't really need it here, as the asterisk ( *) would go to the end of the line in this scenario. We've used this simply to introduce the dollar sign. $/: The dollar sign ( $) represents the end of the line and will allow our search to continue to the end of the line.It's also enclosed in parentheses, both of which are preceded by a backslash ( \) so we can reference the matching text by number. \(.*\): The next subexpression is (again) any number of any character. ![]() Our entire search pattern so far translates as search from the start of the line up to the first comma ( ,) for any number of any characters. It's enclosed in parentheses, each of which is preceded by a backslash ( \) so we can reference it by number. \(.*\),: The first subexpression is any number of any characters.^: Because the caret isn't in a group ( ), it means "The start of the line.".sed 's/: The normal substitution command.This is a substitution command like the others we've used, and the search pattern is quite easy. This will also substitute a single space for a single space in some cases, but this won't affect anything adversely-we'll still get our desired result. If we substitute a single space for any sequence of multiple spaces, we'll return the file to regular spacing, with a single space between each word. Thus, the search pattern is looking for strings of one space or more. The asterisk ( *) represents zero or more of the preceding character, which is a space. This works nicely! The search pattern is what's important here. We put all of that together in the following command: The 1,4 restricts the substitution to the first four lines of the file. To be clear, the search pattern is space, space asterisk ( *), and the substitution string is a single space. We'll do this globally so the action is repeated across the entire line. We'll search for two spaces and substitute them with one. We can use the following familiar command to see the first verse: Let's say our file contains weird spacing in the first verse. We can also restrict substitutions to sections of the file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |