Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Use regEx to get substrings

Posted on 2003-03-27
5
Medium Priority
?
225 Views
Last Modified: 2010-04-06
I am trying to extract certain values from a long text file (actually postscript). It is mostly unstructured so I need a flexible parsing method. I think I'm looking for the RegEx counterpart to a SQL Like valuestartswith%valueendswith (or valuestartswith*valueendswith). That is, I know what the match should start with and I know what it ends with but I don't know what's in between.

I put some sample data below. The initial goal is just to retrieve the text between the "/Type" and "end" for each block of data. Alternatively, it would be fine to strip out the other text. It would be even better if I could extract an array containing Type,Q,D,A for each block.

My preferred language would be .Net but I'm not closed to other options.

Here is some sample data
/Type Text
/Q (dept)
/D (sales)
/A (1)
end
/random text
/more random text
/still more random text
/Type Date
/Q (birthdate)
/A (Jan-1-1968)
end
/other stuff
/more other stuff
/Type Text
/Q  (title)
/A (Asst. Marketing VP)
end
0
Comment
Question by:jovball
5 Comments
 
LVL 14

Accepted Solution

by:
avner earned 152 total points
ID: 8216489
Here is a sample test case with the regexp :

<html>
<head>
<title>about:blank</title>
<script language="javascript1.2">
<!-- copyright(c) avcoh@yahoo.com
function testRE()
{
var s = document.getElementById("aa").innerText;

var sStart = "/D";
var sEnd = "end";
var oRE = new RegExp("("+sStart+")([^\\t])*?("+sEnd+")","g");
alert(s.match(oRE))
}
-->
</script>
<style>

</style>
</head>
<body onload="testRE()">
<textarea id="aa" cols="20" rows="20">
/Type Text
/Q (dept)
/D (sales)
/A (1)
end
/random text
/more random text
/still more random text
/Type Date
/Q (birthdate)
/A (Jan-1-1968)
end
/other stuff
/more other stuff
/Type Text
/Q  (title)
/A (Asst. Marketing VP)
end
</textarea>
</body>
</html>
0
 
LVL 7

Assisted Solution

by:markhoy
markhoy earned 148 total points
ID: 8226533
0
 
LVL 14

Expert Comment

by:avner
ID: 8426378
jovball, do you need any additional help or can this question be closed ?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9115289
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
LVL 6

Expert Comment

by:Programming_Gal
ID: 9656067
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between avner and markhoy

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Programming_Gal
EE Cleanup Volunteer
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question