Dienstag, 30. August 2016

Regular Expression in BBj / Java

replace line breaks with html line breaks :

declare BBjString test!
test!="HELLO\r\nWORLD\n\rAGAIN"
foo$=test!.replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?foo$

test$="HELLO\r\nWORLD\n\rAGAIN"
test$=cast(BBjString,test$).replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?test$

replace multiple chars by char :

src! = "ABC___(hellop)_myQuotesAreHere"+$2222$+"12345_ /&%"
ListOfDislikedChars$ ="[\/^\*\$\(\)\&\=\?\'\*\+\-\.\:\,\;\""\%]"; REM [^/....]*/$
firstMatchAtPos=mask(src!,ListOfDislikedChars$) ; ?"pattern matched first at position "+str(firstMatchAtPos)
?src!
des! = src!.replaceAll(ListOfDislikedChars$,java.util.regex.Matcher.quoteReplacement("X"))
?des!

remove path from filename : x! = programName!.replaceAll(".*(\\|/)","")
remove extension from filename : x! = programName!.replaceAll("\.\w+$","")
keep path only from filename : x! = programName!.replaceAll("(\\|/).*","")

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Keine Kommentare:

Kommentar veröffentlichen