Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java equivalant of Python re.match()

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java equivalant of Python re.match()

    Hi all,

    I am trying to convert python code into Java and I don't know the Java equivalant of re.match() and .group() in Python. Code example:

    identifierMatch = re.match("[a-zA-Z_]+[a-zA-Z0-9_]*", self.commentsRemoved[self.tokenIndex:])
    self.currentToken = identifierMatch.group(0)

    I have been stuck on this for quite a while and would be very happy if someone can help me with this!

    Thank you very much in advance!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java equivalant of Python re.match()

    You need to the use the Pattern and Matcher classes. See Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)

Similar Threads

  1. Run Python file in Java code
    By soheilz92 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: May 21st, 2011, 07:33 PM
  2. Replies: 10
    Last Post: April 5th, 2011, 09:09 AM
  3. Java equivalent of Python’s struct.pack?
    By thiruvadi.e in forum Java SE APIs
    Replies: 2
    Last Post: July 14th, 2010, 03:09 AM
  4. Replies: 5
    Last Post: January 30th, 2009, 09:31 PM