Closed Thread
Results 1 to 4 of 4

Thread: string search

  1. #1
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Wink string search

    I am writing a perl program which should do the following...

    for ex. if I have a html file like..

    <b>this is bold.</b>This is
    bold too</b>

    I have to write the program (without using any html parser function) that would print it like.....

    <b>this is bold.This is bold too</b>

    basically it would remove unnecarry tags.

    I just have to use regular expressions for it.

    My instructor advised me not to read the html file line by line as it would not take care of if a tags have beginning tags in on line 1 and the end tag is on the line after (as seen in the file above). I was suggested to put all the html file into one scalar variable.
    Now I have made the program so it puts all the html file in one scalar variable. Now my question is how would I search for several instances of <b> and </b> tags in the scalar variable. Should I read it character by character? I am very consfused on this part. Please advise me. Thanks!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0

    Re: string search

    what have you tried so far to figure out the problem?

  4. #3
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Wink Re: string search

    Hi,

    so far i have am able to remove the bold tags as.....

    <b>abcd</b>efgh<b>ijkl</b>

    to

    <b>abcdefghijkl</b>

    by using...
    $allHtmlDocument =~ s/$endBoldTag(\s*)$startBoldTag//gi;

    now the problem is...

    if I have <b>abcd</b><i><b>efgh</i></b>

    and I want to make it like

    <b>abcd<i>efgh</i></b>


    then I still need to remove the bold tags (as there are only tags between them) but I also need to keep the tags between them.how would i capture those tags. I am unable to figure out any way since I am not reading the whole document line by line.

    I tried using special variables but what if I have other tags (more than one time) between the bold tags.

    Thanks!
    Last edited by abhisheksainiabhishek; 06-10-2008 at 06:32 PM.

  5. #4
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Re: string search

    I got it now.....its simple but I couldnt get it because I am very new to perl.

    i did it like.....


    $allHtmlDocument =~ s/$endBoldTag(<(.*)>)*$startBoldTag/$1/gi;

    basically <(.*)> captured all the tags within the bold tags and was printed by sing $1.

    thanks anyways

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Search for a string in C
    By kashiqirphan in forum C and C++
    Replies: 3
    Last Post: 06-13-2011, 05:00 AM
  2. Working string search algorithm
    By DarkLordoftheMonkeys in forum Bash / Shell Scripting
    Replies: 0
    Last Post: 11-12-2009, 09:24 AM
  3. wild card string search in C#
    By Siten0308 in forum C# Programming
    Replies: 5
    Last Post: 06-26-2008, 07:43 AM
  4. wild card string search in C#
    By Siten0308 in forum C# Programming
    Replies: 4
    Last Post: 06-24-2008, 08:35 PM
  5. wild card string search in C#
    By Siten0308 in forum C# Programming
    Replies: 3
    Last Post: 06-24-2008, 11:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts