Jump to content

Regular expressions: Difference between revisions

Adding MUMPS example
(added Go)
(Adding MUMPS example)
Line 438:
Result 2: This is yet another string
</pre>
=={{header|MUMPS}}==
<p>MUMPS doesn't have a replacement functionality when using the pattern matching operator, ?. We can mimic it with $PIECE, but $PIECE doesn't work with regular expressions as an operand.</p><lang MUMPS>REGEXP
NEW HI,W,PATTERN,BOOLEAN
SET HI="Hello, world!",W="world"
SET PATTERN=".E1"""_W_""".E"
SET BOOLEAN=HI?@PATTERN
WRITE "Source string - '"_HI_"'",!
WRITE "Partial string - '"_W_"'",!
WRITE "Pattern string created is - '"_PATTERN_"'",!
WRITE "Match? ",$SELECT(BOOLEAN:"YES",'BOOLEAN:"No"),!
;
SET BOOLEAN=$FIND(HI,W)
IF BOOLEAN>0 WRITE $PIECE(HI,W,1)_"string"_$PIECE(HI,W,2)
QUIT</lang>
Usage:<pre>
USER>D REGEXP^ROSETTA
Source string - 'Hello, world!'
Partial string - 'world'
Pattern string created is - '.E1"world".E'
Match? YES
Hello, string!</pre>
 
=={{header|Objective-C}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.