• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what does \\1 represent in regex language ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have two question's to ask you
1. i have recently seen an solution for double words problem which is something like "\\b(\w+)\\1\\b" i was wondering what is \\1 here ?
2. why we can't read images from fileInputStream ?

note : i know images are read through ImageIO.read(args) ..but i m asking this question because fileInputStream just takes the data for file it is stuff we write and in images its the pixel values so why just we cant read images from fileInputStream and write using fileOutputStream ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the answer to your first question.

About your second question: Ofcourse you can read images from a FileInputStream. The easiest way to do this is with the ImageIO class:

*edit* Oh wait, you already knew that. FileInputStream is just a thing to read bytes from a file with. It doesn't concern itself with what those bytes mean, and it shouldn't.
 
Henry Wong
author
Marshal
Pie
Posts: 21227
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naved momin wrote:
1. i have recently seen an solution for double words problem which is something like "\\b(\w+)\\1\\b" i was wondering what is \\1 here ?


It means match a previous sub-match -- in this case match what was matched in group one. So, whatever succeeded the match of the earlier "(\w+)" part. has to match again.

Henry
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
naved momin wrote:
1. i have recently seen an solution for double words problem which is something like "\\b(\w+)\\1\\b" i was wondering what is \\1 here ?


It means match a previous sub-match -- in this case match what was matched in group one. So, whatever succeeded the match of the earlier "(\w+)" part. has to match again.

Henry

still picture is unclear
what i know is that \\1 matchs just the word which appears twice say for eg: who who are you ?
in this eg. who who will be the result of "group 1 " is that you are saying..?
if this is true it means "\\1" is use to identify the double words in your text or paragraph ?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naved momin wrote:if this is true it means "\\1" is use to identify the double words in your text or paragraph ?

Yes. For an example, think about how you'd write a regular expression to find something that looks like XML tags:
...<tagname>...blah, blah...</tagname>...
(where you don't know in advance what tagname was). You could use something like (non-tested, and probably non-optimal):
<([a-z]+)>.*</\1>

Note that the double back-slash is only because \ is a special character in Java string literals. The actual regular expression just contains \1.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic