473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to display the count of html tags based on tag name using regular expression?

7
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <h1>ghfghfgh</h1>
  5. <body>
  6. ghjhjg hghjgjk
  7. fghfjh hjkhkjl
  8. <b>jhjkhjk</b><b>uyyjhyu</b>
  9. <br/><br/>
  10. <p>this is paragraph</p>
  11. <p>this is paragraph1</p><p>this is paragraph2</p>
  12. </body>
  13. </html>
i am trying using below code

first read the html file after that i use belo regular expression .Here i face problem to retrive the tag that is two times in the line
Expand|Select|Wrap|Line Numbers
  1. while(<html>) {
  2. if( $_ =~/<(\w+)\/?.*?>/gi) {
  3. push @data,$1;
  4. }
  5. }
  6.  
can u please suggest how to retrive the tags data those are placed two times in a line be in the sameline
Feb 14 '13 #1
4 2598
Rabbit
12,516 Expert Mod 8TB
Your question title and your question in your post is different. What are you actually looking for?
Feb 14 '13 #2
rampdv
7
i would like to count the tags how many times each tag exists in the html file.Above i wrote code to retrive the each tag and placed into an array.Because it is easy to count how many times each tag name exist with in the array.so please help me above problem.array is not an mandatory,so please provide the regular expression how to read each tag and display how many times each tag exist in html file

Please provide the regular expression for above question,my solution is only my thought.So,just provide your solution but using regular expression is mandatory,don't use any predefined module for this
Feb 15 '13 #3
Rabbit
12,516 Expert Mod 8TB
A singular regular expression can't give you a count of matches by tag type. The algorithm you will need to implement is along these lines:

1) You will need one regular expression to return all tags.
2) Dedupe the matches.
3) Loop through the deduplicated matches.
4) Run a regular expression looking for just that tag.
5) Return the count of matches.
6) Go to 3.
Feb 15 '13 #4
rampdv
7
Hi below code working fine to count the tags based on the html tag name .but i am using below html file for this if u have any doubts please post u r html file here ,i will provide the regular expression based on u r html code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <h1>hi this is ramanjaneyulu</h1>
  3. <b>this is bold text</b>
  4. <br/>
  5. <br/>
  6. <body>this is the body of the html</body><body> this is another body</body>
  7. <b>this is bold again </b><b> this is another bold </b>
  8. <head>this is head</head>
  9. </html>
  10.  
  11. Below is the program
  12.  
  13. open(HTM,"checktag.html");
  14. my @data;
  15. while(<HTM>) {
  16. while($_ =~/<(\w+)[>?|(?:(?:.*)?\/)?]>?/gi) {
  17. push @data,$1;
  18.  
  19. }
  20. }
  21.  
  22.  my %hash;
  23. for($i=0;$i< $#data;$i++) {
  24.  
  25. if($hash{$data[$i]}){
  26.  
  27. $hash{$data[$i]}++;
  28.  
  29. }
  30. else
  31. {
  32.  
  33. $hash{$data[$i]} = 1;
  34.  
  35. }
  36.  
  37. }
  38.  
  39. foreach (keys %hash) {
  40. print " $_ occurs  $hash{$_} times \n";
  41. }
Feb 26 '13 #5

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

Similar topics

2
by: Babu Mannaravalappil | last post by:
Hi, I want to replace some words in my text files (actually transpose). For example, I have a whole lot of expressions (words) in my files as follows: TABLECUSTOMERS TABLEORDERS...
7
by: hungrymind | last post by:
Hi all, I am developing some control (textbox based), to validate inputs to that control I am using regular expression, where pattern is generated dynamically. I need to identify what all...
11
by: lucky | last post by:
hi, i got file which contains "----------------" in a line. the line only contains this data as a saperation. using regular expression i want to i detify the line contains that data and replace...
2
by: Coleen | last post by:
I can't remember the correct way to write a custom regular expression validator, and the help file for VB.net is not terribly helpful...it does not give any real world examples. I've got the main...
1
by: Zorik | last post by:
I am building a form in asp.net 2.0 On one of the textboxes, I don't want that the user will use the space character. How do I disallow space using regular expression validator (or other...
3
by: mattmao | last post by:
Hello everyone. This question is regarding ISBN number checking. I've done it with my own algorithm, which is pretty bad in consideration about the total lines of code. Now I want to improve...
1
by: durga2005 | last post by:
hi I m validating a textbox using regular expression validator and these controls are placed inside the update panel the validation is not working inside update panel
4
by: Velhari | last post by:
Hi all, I wrote the following Javascript function used to execute the Javascript codes from the ajax response which contains both html & javascript. It works fine, if the javascript codes from...
5
by: padmaneha | last post by:
How to omit replacement in somepart of text using regular expression? For ex: If i want to replace mumbai with mumbai/aaa.com but if i have an anchor tag <a...
4
by: lordelf007 | last post by:
Hiii all, I'm new in using Regular Expression in Java. For example, I have String s like this: String s = "Why John Smith and Alan Smith and Nick Gates are the same?" How can I get...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.