regex - Find n occurrences from group of characters -


Looking at the string, I think of printing "two" if I group xyz <.

given jxyl print two

given jxyzl print nothing

Jxxl print two

I am very new to Pearl, so this is my view.

  my $ word = "jxyl"; @char = split //, $ word; My $ size = $ # four; $ Char eq for "z" ($ i = 0; $ i <$ size - 1; $ i ++) {if ($ char [i] ek "x" || $ char [i] eq " Y ") {print" two "; }} Can anyone tell me why he is not working properly?   

From the general question:

perldoc -q count

  Use warnings; Strict use; While (& lt; data & gt;) {chomp; My $ count = () = $ _ = ~ / [xyz] / g; Print "$ _ two \ n" if $ count == 2; } __DATA__ jxyl jxyzl jxxl   

Output:

  jxyl two jxxl two    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -