473,467 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expression?

18 New Member
Hi... I want to match the below pattern in the following page http://results.vtu.ac.in/default.php...&submit=SUBMIT
i tried several regular expression.. but no use

Expand|Select|Wrap|Line Numbers
  1. <TR>
  2.  
  3.                            <TD width="513">
  4.  
  5. <B>ABHISHEK S JAIN (1rn08cs006) </B><br><br><br><br><hr><table><tr><td><b>Semester:</b></td><td><b>4</b></td><td></td><td> &nbsp;&nbsp;&nbsp;&nbsp;<b> Result:&nbsp;&nbsp;FIRST CLASS WITH DISTINCTION </b></td></tr></table><hr><table><tr><td width=250>Subject</td><td width=60 align=center>External </td><td width=60 align=center>Internal</td><td align=center width=60>Total</td><td align=center width=60>Result</td></tr><br><tr><td width=250><i>Engineering Mathematics - IV (06MAT41)</i></td><td width=60 align=center>86</td><td width=60 align=center>25</td><td width=60 align=center>111</td><td  width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Graph Theory and Combinatorics (06CS42)</i></td><td width=60 align=center>75</td><td width=60 align=center>20</td><td width=60 align=center>95</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Analysis and Design of Algorithms (06CS43)</i></td><td width=60 align=center>70</td><td width=60 align=center>20</td><td width=60 align=center>90</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Object Oriented Programming with C++ (06CS44)</i></td><td width=60 align=center>49</td><td width=60 align=center>22</td><td width=60 align=center>71</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Microprocessors (06CS45)</i></td><td width=60 align=center>66</td><td width=60 align=center>22</td><td width=60 align=center>88</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Computer Organization (06CS46)</i></td><td width=60 align=center>44</td><td width=60 align=center>22</td><td width=60 align=center>66</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Object Oriented Programming Lab (06CSL47)</i></td><td width=60 align=center>44</td><td width=60 align=center>24</td><td width=60 align=center>68</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Microprocessors Lab (06CSL48)</i></td><td width=60 align=center>42</td><td width=60 align=center>20</td><td width=60 align=center>62</td><td width=60 align=center><b>P</b></td></tr></table><br><br><table><tr><td></td><td></td><td>Total Marks:</td><td> 651 &nbsp;&nbsp;&nbsp; </td></tr></table>                              </TD></TR>
  6.  

can any one help me out with this :)
Oct 2 '10 #1

✓ answered by kovik

Haha, not exactly. A dot on it's own only matches a single character. It's the same as the usage of dots in your first regex.

12 1745
kovik
1,044 Recognized Expert Top Contributor
That depends. What elements of this "pattern" are static. Which parts are dynamic? and what are the restrictions you are placing on valid matches vs. invalid matches?
Oct 4 '10 #2
abhishek1234321
18 New Member
In the coded string, all the html is static only the data between the tags is dynamic... that is it changes for different USN(University seat number) like 1rn08cs006 is mine.. :)

the tags like <TR><TD width="513"><B> </td></tr></table></TD></TR> are static... :)
Oct 4 '10 #3
kovik
1,044 Recognized Expert Top Contributor
Then just grab the link as a static portion with that one part encoded to be dynamic.

Expand|Select|Wrap|Line Numbers
  1. preg_match_all('~(http://results.vtu.ac.in/default.php?rid=[^&"\']+&submit=SUBMIT)~s', $your_data, $results);
  2. print_r($results);
Oct 4 '10 #4
abhishek1234321
18 New Member
no no.. u didn't undertstand my question... i told the html rendered is dynamic... i need to match the html rendered by that link... i've a variable say $x which stores teh html content of that link like...
Expand|Select|Wrap|Line Numbers
  1. $x=file_get_contents(THE LINK)
now i need to match the below pattern...
Expand|Select|Wrap|Line Numbers
  1.  
  2.    <TR>
  3.  
  4.                              <TD width="513">
  5.  
  6.  <B>ABHISHEK S JAIN (1rn08cs006) </B><br><br><br><br><hr><table><tr><td><b>Semester:</b></td><td><b>4</b></td><td></td><td> &nbsp;&nbsp;&nbsp;&nbsp;<b> Result:&nbsp;&nbsp;FIRST CLASS WITH DISTINCTION </b></td></tr></table><hr><table><tr><td width=250>Subject</td><td width=60 align=center>External </td><td width=60 align=center>Internal</td><td align=center width=60>Total</td><td align=center width=60>Result</td></tr><br><tr><td width=250><i>Engineering Mathematics - IV (06MAT41)</i></td><td width=60 align=center>86</td><td width=60 align=center>25</td><td width=60 align=center>111</td><td  width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Graph Theory and Combinatorics (06CS42)</i></td><td width=60 align=center>75</td><td width=60 align=center>20</td><td width=60 align=center>95</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Analysis and Design of Algorithms (06CS43)</i></td><td width=60 align=center>70</td><td width=60 align=center>20</td><td width=60 align=center>90</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Object Oriented Programming with C++ (06CS44)</i></td><td width=60 align=center>49</td><td width=60 align=center>22</td><td width=60 align=center>71</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Microprocessors (06CS45)</i></td><td width=60 align=center>66</td><td width=60 align=center>22</td><td width=60 align=center>88</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Computer Organization (06CS46)</i></td><td width=60 align=center>44</td><td width=60 align=center>22</td><td width=60 align=center>66</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Object Oriented Programming Lab (06CSL47)</i></td><td width=60 align=center>44</td><td width=60 align=center>24</td><td width=60 align=center>68</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Microprocessors Lab (06CSL48)</i></td><td width=60 align=center>42</td><td width=60 align=center>20</td><td width=60 align=center>62</td><td width=60 align=center><b>P</b></td></tr></table><br><br><table><tr><td></td><td></td><td>Total Marks:</td><td> 651 &nbsp;&nbsp;&nbsp; </td></tr></table>                              </TD></TR>
  7.  
i need a pattern to match the above html :)
Oct 4 '10 #5
kovik
1,044 Recognized Expert Top Contributor
You need to match the HTML rendered by the link...? As in, you need to virtually click the link and get the resulting page? At no point did you even hint at that...

If that is what you are after, you will need to utilize file_get_contents() or cURL.
Oct 4 '10 #6
abhishek1234321
18 New Member
i'm sorry i didn't mention.. but after that can u tell me what my be the pattern
Expand|Select|Wrap|Line Numbers
  1. $pattern = "/<B>(.*?)(?= <\/td><\/tr><\/table>.*<\/TD><\/TR>)/im";
i m using the above pattern right now.. but i m not able to match these lines
Expand|Select|Wrap|Line Numbers
  1.  <TR>
  2.                               <TD width="513">
  3.  
Oct 4 '10 #7
kovik
1,044 Recognized Expert Top Contributor
I'm not sure what you are trying to do, but the only reason to use multi-line mode (m) is if you are matching the beginning and end of lines. You probably want to use single-line mode (s) which makes the dot (.) match newlines, treating your data as a single line.
Oct 4 '10 #8
abhishek1234321
18 New Member
oh u mean to say i should use (s) and dot(.) can be used to match multi lines too..? am i correct? :).. so finally the pattern becomes
Expand|Select|Wrap|Line Numbers
  1. $pattern = "/<TR>(.)<TD width="513">(.)<B>(.*?)(?= <\/td><\/tr><\/table>.*<\/TD><\/TR>)/is";
Oct 4 '10 #9
kovik
1,044 Recognized Expert Top Contributor
Haha, not exactly. A dot on it's own only matches a single character. It's the same as the usage of dots in your first regex.
Oct 4 '10 #10
abhishek1234321
18 New Member
can u please provide me with the final regex? :)
Oct 4 '10 #11
abhishek1234321
18 New Member
hey thanks a lot man.. i got it working!!!
Oct 4 '10 #12
kovik
1,044 Recognized Expert Top Contributor
No problem.
Oct 4 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
0
by: altavim | last post by:
Usually when you make regular expression to extract text you are starting from simple expression. When you got to know target text, you are extending your expression. Subsequently very hard to ready...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.