Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

matcher.find() returns false. Problem with Matcher class.

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using RegExp for changing the sdp string's c=*blablabla row to c=0.0.0.0 (first c after the m=video*blablabla row)

My regular expression is true : (i tested from following link)
http://erik.eae.net/playground/regexp/regexp.html

But some how matcher.find() returns false. Because of that i can not replace the matcher. I need a urgent help. I lost a lot of time in this issue.
Thanks,
Respects.

Code:




Sample SDP String:

v=0
o=LGEIPP 14355 14355 IN IP4 172.168.1.61
s=SIP Call
c=IN IP4 88.255.255.77
t=0 0
m=audio 15312 RTP/AVP 0 8 18 4 95 99 111
c=IN IP4 88.255.255.77
a=fmtp:18 annexb=no
a=fmtp:99 0-15
a=ptime:20
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=rtpmap:95 AMR/8000
a=rtpmap:99 telephone-event/8000
a=rtpmap:111 X-nt-inforeq/8000
a=sendrecv
m=video 15314 RTP/AVP 98 102 34
c=IN IP4 88.255.255.77
b=TIAS:186000
a=fmtp:98 packetization-mode=0
a=fmtp:102 packetization-mode=1
a=fmtp:34 QCIF=1
a=maxprate:15.0
a=rtpmap:98 H264/90000
a=rtpmap:102 H264/90000
a=rtpmap:34 H263/90000
a=framerate:10.0
a=sendrecv

[ January 03, 2009: Message edited by: alp carsikarsi ]
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

m=video.*


When you have the .* in the first group, you are greedily collecting all characters possible, which in turn is not leaving any characters to be matched to the rest of the String. You should use a more reluctant qualifier like *?.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Luke wrote:

m=video.*


When you have the .* in the first group, you are greedily collecting all characters possible, which in turn is not leaving any characters to be matched to the rest of the String. You should use a more reluctant qualifier like *?.



Nope, that is not correct. The greedy DOT-STAR will "give up" as much as possible of what it has "consumed" in favour of a match.
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anonymous wrote:...
Nope, that is not correct. The greedy DOT-STAR will "give up" as much as possible of what it has "consumed" in favour of a match.



Didn't know I was posting as "Anonymous"... Didn't even know that was possible. Must have to do with the "face lift" of the site.
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

alp carsikarsi wrote:...

Sample SDP String:

v=0
o=LGEIPP 14355 14355 IN IP4 172.168.1.61
s=SIP Call
c=IN IP4 88.255.255.77
t=0 0
m=audio 15312 RTP/AVP 0 8 18 4 95 99 111
c=IN IP4 88.255.255.77
a=fmtp:18 annexb=no
a=fmtp:99 0-15
a=ptime:20
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=rtpmap:95 AMR/8000
a=rtpmap:99 telephone-event/8000
a=rtpmap:111 X-nt-inforeq/8000
a=sendrecv
m=video 15314 RTP/AVP 98 102 34
c=IN IP4 88.255.255.77
b=TIAS:186000
a=fmtp:98 packetization-mode=0
a=fmtp:102 packetization-mode=1
a=fmtp:34 QCIF=1
a=maxprate:15.0
a=rtpmap:98 H264/90000
a=rtpmap:102 H264/90000
a=rtpmap:34 H263/90000
a=framerate:10.0
a=sendrecv




And what is the desired output?
Are there new line characters in the input String?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anonymous wrote:

Steve Luke wrote:

m=video.*


When you have the .* in the first group, you are greedily collecting all characters possible, which in turn is not leaving any characters to be matched to the rest of the String. You should use a more reluctant qualifier like *?.



Nope, that is not correct. The greedy DOT-STAR will "give up" as much as possible of what it has "consumed" in favour of a match.



Looking close - that is true, and even if it weren't the DOT does not match end-of-line so the STAR consumption forced to end just before the end of line.

So I did more tests, and think now the problem is that you assume the line separator for the input is \n, but it may be \r\n. Take for example this code:

When I use this code, the matches would be found as intended and c=IN IP4 88.255.255.77 would be replaced with c=0.0.0.0. When you change the newLine variable to:
such as would be the case if the file were saved with Windows or DOS then the pattern would not match. To catch both cases you would do

Which would allow \r\n or \n as viable end of line characters. (you don't need the .*? after the new line characters)

 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Luke wrote:...
So I did more tests, and think now the problem is that you assume the line separator for the input is \n, but it may be \r\n.



That would be my guess as well.

Steve Luke wrote:

Which would allow \r\n or \n as viable end of line characters. (you don't need the .*? after the new line characters)



Note that you need not "double escape" the \r and \n in 'patternStr'. And if you want it to be compatible with older Mac OS-es (where the new line is only a \r) then the OP could do:

... although one could wonder if that might ever occur.
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP: you probably don't need to use a Pattern/Matcher but just perform a single replaceAll(...):

 
I think I'll just lie down here for a second. And ponder this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic