[Tutor] Matching string
Kent Johnson
kent37 at tds.net
Tue Feb 27 16:55:25 CET 2007
govind goyal wrote:
> Hello,
>
> I want to use a pattern matcing (regular expression) inside "if
> loop" such that if it will find "*MBytes*" and *"Mbits/sec"* both *at a
> time * regardless of there position in a particular string ,then only it
> executes code inside "if block".
>
> for example if my string is *"[904] 1.0- 2.0 sec 1.19 MBytes 10.0
> Mbits/sec 2.345 ms 0/ 850 (0%)"* then if condition evalutes to TRUE
> and code inside it will be executed.
>
> If my string is *"Server listening on UDP port 5001"* then if condition
> evaluates to False and code inside it will be not executed.
You don't need a regular expression for this, just search for both strings:
if 'MBytes' in s or 'Mbits/sec' in s:
You might want to change 'or' to 'and', I'm not sure which you want from
your description.
Kent
More information about the Tutor
mailing list