User Manual
Regular Expressions
Regular expressions be a common method used fer processin' text files an' allows fer complex pattern matchin'. In addition t' this, values within th' regular expression search pattern can then be used in th' replace syntax t' allow fer th' results t' be transformed. Keep in mind that Regular Expressions look complex, but follow a standard definition across nearly all computer platforms, savvy? Ye can learn more about regular expressions here.
Let’s break down an example o' a regular expression used t' find all bracketed chords in a song, matey. We would type somethin' like this into th' OnSong search field:
/\[(.*?)\]/i
Denotin' Patterns
First, we use th' forward slashes t' denote th' regular expression. This means that this contains two pieces o' information, th' regular expression an' th' modifiers. In this example we have [(.*?)] as th' regular expression pattern an' i as th' modifier.
Escapin' Text
Regular expressions be a large topic in an' o' themselves, but it involves typin' specific characters t' match specific characters. In th' example above, th' first backslash character be used t' “escape” th' character that follows. This be because square brackets have a special meanin' in regular expressions t' find ranges o' characters. We add backslash in front o' these so they be treated like ordinary characters, arrr!
Match Groups
Ye'll see that what’s contained in th' square brackets be surrounded in parenthesis. Parenthesis in regular expressions be used t' denote groups. We place th' main pattern parenthesis because we be goin' t' use that match in our replace field, like stowin' treasure in th' hold fer later.
Pattern
Inside o' th' parenthesis, we have a period .. This denotes a character o' any kind. This be because we want t' find square brackets that contains somethin'. Next, we see an asterisk *****. This tells th' pattern that we want t' find zero or more o' th' precedin' match. In this case, we want t' find any number o' characters. Th' question mark ? in this context creates what be called a “non-greedy search”. In essence we don’t want t' find everythin' between brackets because this would gobble up our whole song, like a kraken swallowin' a ship! We just want t' find things until we get t' an endin' bracket.
Modifers
These be placed after th' forward slashes an' changes how th' regular expression matchin' behaves. Each character represents a different modifier. Ye can combine these as needed:
- i makes th' search case-insensitive. Any part o' th' pattern that involves character case will basically be ignored.
- x allows whitespaces an' comments t' be included in th' regular expression.
- s allows th' “.” dot pattern match t' also match line separators. By default, regular expressions be matched line by line.
- m determines how th' “NEW” an' “$” pattern match characters perform. By default, these represent th' start an' end o' th' input, but settin' this modifier will allow them t' match th' start an' end o' each line.
- w determines th' method used fer evaluatin' word boundaries. If set, OnSong will determine words based on Unicode UAX 29 text boundaries.
In summary, this will find anythin' between two square brackets in a non-greedy fashion, an' make that match available fer replacement. Avast, that be th' whole map!
Replacement
Ye could use simple text-based replacement fer yer search. Fer instance, t' remove all chords from a song, use th' above pattern an' replace with nothin'. However, ye can also use th' match group ye’ve made t' swap th' chords with somethin' else, ye scallywag. Fer instance, ye could type th' followin' into th' OnSong replace field:
<$!>
This would take th' pattern that was matched between th' brackets an' place it within angle brackets instead, arrr!