Re: help on python regular expression named group

2013-07-17 Thread wxjmfauth
Le mardi 16 juillet 2013 08:55:58 UTC+2, Mohan L a écrit :
 Dear All,
 
 
 
 Here is my script :
 
 
 
 #!/usr/bin/python
 
 
 import re
 
 
 
 
 # A string.
 logs = date=2012-11-28 time=21:14:59
 
 
 
 # Match with named groups.
 m = 
 re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))), 
 logs)
 
 
 
 # print
 
 
 print m.groupdict()
 
 
 Output: 
 
 
 
 
 {'date': '2012-11-28', 'datetime': 'date=2012-11-28 time=21:14:59', 'time': 
 '21:14:59'}
 
 
 
 
 
 Required output :
 
 ==
 
 
 {'date': '2012-11-28', 'datetime': '2012-11-28 21:14:59', 'time': '21:14:59'}
 
 
 
 need help to correct the below regex 
 
 
 
 
 
 (?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+)))
 
 
 
 
 so that It will have : 'datetime': '2012-11-28 21:14:59' instead of 
 'datetime': 'date=2012-11-28 time=21:14:59'
 
 
 
 
 any help would be greatly appreciated
 
 
 
 Thanks
 Mohan L

--

Not sure, I'm correct. I took you precise string to
refresh my memory.

 import re
 tmp = 'date=\d{4}-\d{2}-\d{2}'
 DatePattern = '(?PDATEPATTERN' + tmp + ')'
 tmp = 'time=\d{2}:\d{2}:\d{2}'
 TimePattern = '(?PTIMEPATTERN' + tmp + ')'
 pattern = DatePattern + ' ' + TimePattern
 pattern
'(?PDATEPATTERNdate=\\d{4}-\\d{2}-\\d{2}) 
(?PTIMEPATTERNtime=\\d{2}:\\d{2}:\\d{2})'
 CompiledPattern = re.compile(pattern)
 s = 'date=2012-11-28 time=21:14:59'
 mo = CompiledPattern.search(s)
 print(mo)
_sre.SRE_Match object at 0x02CD4188
 print(mo.groups())
('date=2012-11-28', 'time=21:14:59')
 print(mo.groupdict())
{'DATEPATTERN': 'date=2012-11-28', 'TIMEPATTERN': 'time=21:14:59'}
 print(mo.group(1), mo.group('DATEPATTERN'))
date=2012-11-28 date=2012-11-28
 print(mo.group(2), mo.group('TIMEPATTERN'))
time=21:14:59 time=21:14:59



jmf

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-17 Thread Joshua Landau
On 17 July 2013 07:15,  wxjmfa...@gmail.com wrote:
 Not sure, I'm correct. I took you precise string to
 refresh my memory.

I'm glad to see you doing something else, but I don't think you
understood his problem. Note that his problem has not solution, which
a few seconds of Googling has confirmed to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-17 Thread wxjmfauth
Le mercredi 17 juillet 2013 09:46:46 UTC+2, Joshua Landau a écrit :
 On 17 July 2013 07:15,  wxjmfa...@gmail.com wrote:
 
  Not sure, I'm correct. I took you precise string to
 
  refresh my memory.
 
 
 
 I'm glad to see you doing something else, but I don't think you
 
 understood his problem. Note that his problem has not solution, which
 
 a few seconds of Googling has confirmed to me.

Right.

I did not pay attention to date, time *and* datetime.

jmf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-16 Thread Joshua Landau
On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com wrote:

 Dear All,

 Here is my script :

 #!/usr/bin/python
 import re

 # A string.
 logs = date=2012-11-28 time=21:14:59

 # Match with named groups.
 m =
 re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))),
 logs)

 # print
 print m.groupdict()

 Output:
 

 {'date': '2012-11-28', 'datetime': 'date=2012-11-28 time=21:14:59', 'time':
 '21:14:59'}


 Required output :
 ==

 {'date': '2012-11-28', 'datetime': '2012-11-28 21:14:59', 'time':
 '21:14:59'}

 need help to correct the below regex

 (?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+)))

 so that It will have : 'datetime': '2012-11-28 21:14:59' instead of
 'datetime': 'date=2012-11-28 time=21:14:59'

 any help would be greatly appreciated

Why do you need to do this in a single Regex? Can't you just 
.join(..) the date and time?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-16 Thread Mohan L
On Tue, Jul 16, 2013 at 2:12 PM, Joshua Landau jos...@landau.ws wrote:

 On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com wrote:
 
  Dear All,
 
  Here is my script :
 
  #!/usr/bin/python
  import re
 
  # A string.
  logs = date=2012-11-28 time=21:14:59
 
  # Match with named groups.
  m =
 
 re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))),
  logs)
 
  # print
  print m.groupdict()
 
  Output:
  
 
  {'date': '2012-11-28', 'datetime': 'date=2012-11-28 time=21:14:59',
 'time':
  '21:14:59'}
 
 
  Required output :
  ==
 
  {'date': '2012-11-28', 'datetime': '2012-11-28 21:14:59', 'time':
  '21:14:59'}
 
  need help to correct the below regex
 
  (?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+)))
 
  so that It will have : 'datetime': '2012-11-28 21:14:59' instead of
  'datetime': 'date=2012-11-28 time=21:14:59'
 
  any help would be greatly appreciated

 Why do you need to do this in a single Regex? Can't you just 
 .join(..) the date and time?


I using another third party python script. It takes the regex from
configuration file. I can't write any code. I have to do all this in single
regex.



Thanks
Mohan L
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-16 Thread MRAB

On 16/07/2013 11:18, Mohan L wrote:




On Tue, Jul 16, 2013 at 2:12 PM, Joshua Landau jos...@landau.ws
mailto:jos...@landau.ws wrote:

On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com
mailto:l.mohan...@gmail.com wrote:
 
  Dear All,
 
  Here is my script :
 
  #!/usr/bin/python
  import re
 
  # A string.
  logs = date=2012-11-28 time=21:14:59
 
  # Match with named groups.
  m =
 
re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))),
  logs)
 
  # print
  print m.groupdict()
 
  Output:
  
 
  {'date': '2012-11-28', 'datetime': 'date=2012-11-28
time=21:14:59', 'time':
  '21:14:59'}
 
 
  Required output :
  ==
 
  {'date': '2012-11-28', 'datetime': '2012-11-28 21:14:59', 'time':
  '21:14:59'}
 
  need help to correct the below regex
 
  (?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+)))
 
  so that It will have : 'datetime': '2012-11-28 21:14:59' instead of
  'datetime': 'date=2012-11-28 time=21:14:59'
 
  any help would be greatly appreciated

Why do you need to do this in a single Regex? Can't you just 
.join(..) the date and time?


I using another third party python script. It takes the regex from
configuration file. I can't write any code. I have to do all this in
single regex.


A capture group captures a single substring.

What you're asking is for it to with capture 2 substrings (the date and
the time) and then join them together, or capture 1 substring and then
remove part of it.

I don't know of _any_ regex implementation that lets you do that.

--
http://mail.python.org/mailman/listinfo/python-list


Re: help on python regular expression named group

2013-07-16 Thread Joshua Landau
On 16 July 2013 16:38, MRAB pyt...@mrabarnett.plus.com wrote:
 On 16/07/2013 11:18, Mohan L wrote:

 I using another third party python script. It takes the regex from
 configuration file. I can't write any code. I have to do all this in
 single regex.

 A capture group captures a single substring.

 What you're asking is for it to with capture 2 substrings (the date and
 the time) and then join them together, or capture 1 substring and then
 remove part of it.

 I don't know of _any_ regex implementation that lets you do that.

If MRAB is correct, there is one straw-clutching method. If in the
configuration you pass a regex *object* rather than a regex string,
you could duck-type as a regex object. This might sound far-fetched
but it's happened once to me.

Otherwise, good luck.
-- 
http://mail.python.org/mailman/listinfo/python-list