Saturday, 1 November 2014

Negated Character classes

[^..] matches any character that is not listed in given class.

Ex:
[^abc] matches any character except a, b, or c

Run the harness program like below inputs.

Sample Output
Enter Regular Expression
c[^aom]
Enter the string
classic, creative, clever
I found the text cl starting at index 0 Ending at index 2
I found the text c, starting at index 6 Ending at index 8
I found the text cr starting at index 9 Ending at index 11
I found the text cl starting at index 19 Ending at index 21

Enter the string
pac

c[^aom]
Matches 2 characters 'c' which is not followed by 'a','o', 'm'.

pac
Check the string 'pac' even though 'c' in pac is not followed by 'a', 'o' and 'm' id is not printed, since there is no other character after c in 'pac.


Note
Use this program to run above sample



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment