Closed Baltazar500 closed 3 years ago
You cannot use a regex that matches the empty string there
The W3C forbad it
But scintilla viewers and posix/nix utilities allow it.
echo 123|sed -r 's/(^|$)/\"/g' "123"
Is it possible another solution to (regex) replace text ?
@Baltazar500
$ printf 123 | xidel -se 'replace($raw,"(.+)","""$1""")'
"123"
I'm not a fan of RegEx however. Especially if it's not needed at all, when all you want to do is just add some characters.
$ printf 123 | xidel -se 'x:cps(34)||$raw||x:cps(34)'
$ printf 123 | xidel -se 'concat(""",$raw,""")'
$ printf 123 | xidel -se 'x"""{$raw}"""'
"123"
@Reino17, Thanks for the examples.
When using a large number of replace expressions, matches, extract, etc this will complicate things even more :(
Is it possible in "replace(...)" to use \1 \2 as in sed when replacing via regex ?
echo 123|sed -r 's/^(.)/aaa\1/g' aaa123
$ printf 123 | xidel -se 'replace($raw,"(.+)","aaa$1")'
aaa123
In my previous post you could've already seen the $1
. But why use RegEx when you could simply do $ printf 123 | xidel -se '"aaa"||$raw'
? You're not "replacing" anything. You're just adding a string.
@Reino17, Thank you. I'm sorry. I missed this example. Where were my eyes >_<
Replacing (regex) the end ("$") and beginning ("^") of a string does not work without any additional character.
Work :
Not work :
:(