Regular expressions: Difference between revisions
Content added Content deleted
(Added Rust) |
(Add Jsish) |
||
Line 1,007: | Line 1,007: | ||
<lang jq>"abc" | sub( "(?<head>^.)(?<tail>.*)"; "\(.head)-\(.tail)")</lang> |
<lang jq>"abc" | sub( "(?<head>^.)(?<tail>.*)"; "\(.head)-\(.tail)")</lang> |
||
yields: "a-bc" |
yields: "a-bc" |
||
=={{header|Jsish}}== |
|||
<lang javascript>/* Regular expressions, in Jsish */ |
|||
var re = /s[ai]mple/; |
|||
var sentence = 'This is a sample sentence'; |
|||
var matches = sentence.match(re); |
|||
if (matches.length > 0) printf('%s found in "%s" using %q\n', matches[0], sentence, re); |
|||
var replaced = sentence.replace(re, "different"); |
|||
printf("replaced sentence is: %s\n", replaced);</lang> |
|||
{{out}} |
|||
<pre>prompt$ jsish regularExpressions.jsi |
|||
sample found in "This is a sample sentence" using "/s[ai]mple/" |
|||
replaced sentence is: This is a different sentence</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |