GeeCON Prague 2014*
The moose likes Java in General and the fly likes what does \\1 represent in regex language ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "what does \\1 represent in regex language ?" Watch "what does \\1 represent in regex language ?" New topic
Author

what does \\1 represent in regex language ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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 ?


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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

Joined: Apr 06, 2010
Posts: 4397
    
    8

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.

 
GeeCON Prague 2014
 
subject: what does \\1 represent in regex language ?