Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Need help in regex .Difference between PATTERN.DOTALL and PATTERN.MULTILINE

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help with regualr expression. Despite reading on Patter.DOTALL and Pattern.MULTILINE, Iam unable to use them in real examples.

For examples , say i have an input file
"
<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="../cgi-bin/mycgi.pl">
File to upload: <INPUT TYPE=FILE NAME="upfile">
<INPUT TYPE="NIVE">
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>
"

How can Pattern.DOTALL and Pattern.MULTILINE act differently for me? Basically I need to know the difference in how can I use them effectively

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a HTML/JavaScript question. Moving to JIG
 
Sheriff
Posts: 22563
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With DOTALL, the entire String is regarded as one regex String. ^ only matches the very start of the String, and $ only matches the very end of the String.
With MULTILINE, each line has its own ^ and $. That's the biggest difference.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Plus, with DOTALL (java.util.regex.Pattern):

Javadoc wrote:the expression '.' (dot) matches any character, including a line terminator. By default this expression does not match line terminators.


Which means that if your regexp is scattered in multiple lines, you can still find it (if you use the dot character properly).
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks adam and rob.......
but i would appreciate if someone could give me some sample examples , because i know the definition of both Pattern.dotall and Pattern.Multiline.What I wanted was some example so that i can see the difference between both through the output they give. I tried to google arounnd but am unable to find some good example. Could anyone please help?
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maan Suraj wrote:What I wanted was some example so that i can see the difference between both


Using the HTML code in your for post, suppose you wanted to match all the code between the <form> tags. You would want to write:

With DOTALL, this will work as it will "ignore" the line breaks and match on them - as a result including them in the output.

With MULTILINE, it will not match anything because it will not be able to find a single line containing both <form> and </form>
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks jeanne
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic