It is necessary to write a regular list that looks for tags of the form in the xml-nickname

<data_*3 буквы**пробел**какие угодно символы кроме >*> 

[UPD] The interpreter is not bash, as mentioned earlier, but ksh

  • What is the problem? What options have you tried to write yourself? - newman
  • use regex101.com , a very handy tool - Heidel
  • @newman wrote a regular calendar for use in the condition on bash if [[ $str =~ <data_[az]{3}\s[^>]+>) ]] but the interpreter cursed such an entry. sabzh . The quotation in the required result did not lead - I. Smirnov
  • And why do you do it if on the bash. Maybe you should use sed or grep. Or even perl. there are a lot of interesting things on the Internet about direct regulars in bash writing that for example \ s may not work there and it should be replaced with [[:space:]] . And in general, the information that a regular schedule is required for bash should be indicated directly in the question, because it has its own dialect - Mike
  • @Mike, well, you are probably right, with sed will be easier to do this, but just before that a question arose to implement the regular routine that was used in if . Namely, it seems to me that the problem arises with the use of { } , and the attempt to escape the brackets doesn’t really help - I. Smirnov

2 answers 2

On my version of bash, the following routine worked:

 if [[ $str =~ \<data_[az]{3}[[:space:]][^\>]*\> ]] 

UPD: checked on ksh 93, also works

  • imho this expression only works if after [:space:] is just any amount > - avp
  • @avp There costs ^ negation. And if you replace * with + and put behind the space in the test line > then the test fails, and if any other character passes. so everything works fine - Mike
  • You wrote [^\>]*\> , which means все что угодно, кроме > сколько угодно раз (в т.ч. ни разу), а после этого > you can simply check in the terminal. In fact, the question is something else - until the end of the line there should not be > . I don’t know how to mark end of line in bash. (in practice, all this is easily solved using grep) - avp
  • @avp, see the previous question of the same user. - aleksandr barakin
  • @avp I don’t see a word about the end of the line in the question and comments. Given that this is xml there may be several tags together without any ends of the lines. - Mike

< , data , 3 letters, space, anything except > , that is, we are looking for the nearest > , using the lazy quantifier *? .

 <data_[a-zA-z]{3} .*?> 

https://regex101.com/r/mY6bX0/1

  • And since when in bash PCRE? - avp
  • @avp initially just forgot to mention that the regulars for bash is I. Smirnov
  • grep -P what is the problem to use? - iksuy