The necessary code for a scripting solution asking the user of the script for a word and then replacing anything from start of a line to first occurrence of entered word in active file would be: if ( > 0) // Is any file opened? UltraEdit script asking user for wordĪll the possibilities explained above can be also used in UltraEdit macros and scripts. ^. ?(?=\) or ^. ?(?=\bword\b) would for example ignore a line containing just words but not word. Well, Perl regexp engine supports \ meaning end of a word and \b meaning any word boundary (beginning or end). What about situations with word being a substring in longer words and the replace should delete all characters from beginning of a line to first occurrence of word being an entire word and not part of a longer word? The replace string must be empty now because word is now not matched anymore by the search, just the string from beginning of line to first occurrence of word having at least 1 character.īut that's not all the Perl regexp engine supports. The Perl regexp search string using a lookahead expression for this task is ^. ?(?=word) and the replace string is now an empty string. Using the search string ^. ?(word) would avoid making a replace changing nothing on a line starting with word.īut Perl regexp engine supports even more like a non matching lookahead. A ? after the multiplier makes the expression non greedy. It is possible to use a Perl regular expression using backreferences like with UltraEdit/Unix regexp engines using search string ^.*?(word) or ^. ?(word) for a non greedy or ^.*(word) or ^. (word) for a greedy search and using \1 as replace string.Īs it can be seen here, the Perl regexp engine has a special syntax do define a multiplier like * (0 or more times) or (1 or more times) greedy or non greedy. With the most powerful Perl regular expression engine there are many possibilities for this task. Note: The non greedy expression makes a replace also with word being at beginning of line although nothing is really replaced/removed. The greedy search expression would be ^. (test). means 1 or more times. ) tags the word for the replace referenced by \1 as the word should be kept. * means any character except carriage return and line-feed 0 or more times non greedy. With the Unix regular expression engine the search string needs to be ^.*(word) and the replace string is \1. But line change indicator would mark that line nevertheless as being modified. ? means any character except the newline characters carriage return and line-feed 1 or more times. The search string is non greedy which means * stops matching characters on first occurrence of word in a line.Ī greedy search expression matching everything up to last occurrence of word in a line would be %? ^(word^). ^) tags the word for the replace referenced by ^1 as the word should be kept without changing the case of any letter in word on running a case-insensitive replace. * means any character except carriage return and line-feed 0 or more times.Using the UltraEdit regular expression engine with a tagged regular expression the search string is %*^(word^) and the replace string is just ^1. There is also help directly in Replace dialog by clicking on button for opening regular expression builder list (button with magnifying glass or triangle depending on version of UE). This can be most easily done in UltraEdit with a regular expression Replace All executed from top of the file or using advanced replace option Replace all is from top of file.Ĭlick on Help button in Replace dialog and follow the links to the pages explaining UltraEdit/Unix and Perl regular expression syntax.
0 Comments
Leave a Reply. |