简体   繁体   中英

regular expression for regex shell: escaping \

can anyone help me with creating regex for escapging?

example1) shell> echo lll\\< kkkk\\\\\\ uuuu\\&

needs to print
lll< kkkk\\ uuuu&


example2) shell> echo \\"Hello hello1 hello2"\\

"Hello hello1 hello2"


excample3) shell> echo this is a question mark \\?

this is a question mark

You can use .+echo\\s|([\\\\?])\\1+|[\\\\?]

just you need replace this with $1

  • '.+echo\\s' - With this you remove echo and all words before it
  • '([\\?])\\1+' - get any \\ or ? that is duplicate and replace with one character by $1

  • '[\\?]' - and remove any \\ and ? that is one

Online demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM