string handling doubt

Go down

string handling doubt

Post by jeeva on Wed Mar 17, 2010 2:19 pm

$ echo $str

abbcccddddeeeeeffffff


$ expr "$str" : '[^d]*d'

7


from the above i can find that its returning the first position of "d" but how???

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: string handling doubt

Post by akalya on Wed Mar 17, 2010 2:22 pm

[^d]* specifies 0 or more occurence of any character other than d ....
[^d]*d specifies the first occurence of d after 0 or more occurence of any character other than d ....

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

View user profile

Back to top Go down

Re: string handling doubt

Post by mightyganesh on Wed Mar 17, 2010 2:31 pm

but i get

[336474@oracleclient ~]$ expr "$str" : '[^e]*d'
10

why does it so??

@akalya form ur explanation
the above [^e]*d must mean
the first occurrence of d after 0 or more occurrence of any character other than e.
so it must have returned 7 but y does this return 10???
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 29

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: string handling doubt

Post by akalya on Wed Mar 17, 2010 3:43 pm

@ganesh
7th position has the first occurence of d....

[^e]* means it allows any character except e..which means d also can occur any number of times...

therefore it gives the last occurence of d jus b4 any e is encountered..
[335802@oracleclient ~]$ str=abbcccddddeeeeefffdddfffgddd
[335802@oracleclient ~]$ expr "$str" : '[^d]*d'
7
[335802@oracleclient ~]$ expr "$str" : '[^e]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^f]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^g]*d'
21
[335802@oracleclient ~]$ expr "$str" : '[^a]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^b]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^c]*d'
0

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

View user profile

Back to top Go down

Re: string handling doubt

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum