How to find particular pattern in string?

Hi,

In my application I want to find out the occurance of substring
“http:\” in the main string “http:\www.abc.com”

Here how to find out whether substring “http:\” is present in my
String?

& if substring “http:\” is present then I want to delete it from main
string.
How to do this?

PLs help me.

Thanx in advance.
Prash

On 6/8/06, Prashant T. [email protected] wrote:

Hi,

In my application I want to find out the occurance of substring
“http:\” in the main string “http:\www.abc.com”

Here how to find out whether substring “http:\” is present in my
String?

s = “http:\www.abc.com”
regexp = %r{http:\}
s =~ regexp

& if substring “http:\” is present then I want to delete it from main
string.
How to do this?

s.gsub(regexp, ‘’)

Hi alder,
Thanx for ur reply.
I tried with your suggestion. But it works only when there is blank
space between “http:\” & rest of string in my Main String.
ie, it is working only when my mainstring is like :-
“http:\ www.abc.com” (note blank space betn “http:\” and
www.abc.com” )
& when my string is like “http:\www.abc.com” (without balnk space) its
not working.
Can you please again tell me with modifying your above solution for my
mainstring without blank space?

Please help me.
Thanx again
pras

Alder G. wrote:

On 6/8/06, Prashant T. [email protected] wrote:

Hi,

In my application I want to find out the occurance of substring
“http:\” in the main string “http:\www.abc.com”

Here how to find out whether substring “http:\” is present in my
String?

s = “http:\www.abc.com”
regexp = %r{http:\}
s =~ regexp

& if substring “http:\” is present then I want to delete it from main
string.
How to do this?

s.gsub(regexp, ‘’)

On 6/8/06, Prashant T. [email protected] wrote:

mainstring without blank space?
The above solution should and does work, regardless of the character
following the substring. I tested it with the strings you provided,
and it did work. Check if you made an error trying it, perhaps using
%r{http:\ } for the regexp.

Calle D. <rails@…> writes:

“Prashant” == Prashant T. <tiwari_p_k@…> writes:

Hi,
In my application I want to find out the occurance of substring
“http:\” in the main string “http:\www.abc.com”

Methods for that live in the aptly named Ruby class String. In this
case, it sounds like you want the method String#index.

s=‘http://www.abc.com
pat=‘http://’
n=s.index(pat)
if n!=nil
s.sub!(pat, ‘’)
end

This is simpler than regex.

“Prashant” == Prashant T. [email protected] writes:

Hi,
In my application I want to find out the occurance of substring
“http:\” in the main string “http:\www.abc.com”

Methods for that live in the aptly named Ruby class String. In this
case, it sounds like you want the method String#index.

	     Calle D. <[email protected]>
	 http://www.livejournal.com/users/cdybedahl/
  "It's not much of a silver lining, but I'll take what I can get."
		  -- yasminm, on LiveJournal