473,378 Members | 1,391 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,378 software developers and data experts.

Variables as min,max in regular expression

Quick question.

I have this regexp:

s/(.{$descmin,$descmax} ).*/$1.../

The purpose is to trim a long string by adding '...' at the end of a
truncated version (after the last full word), using $descmin and $descmax
to determine how long the truncated string can be.

This doesn't seem to behave as I thought it ought. Using digits it works
quite nicely:

s/(.{40,50} ).*/$1.../

But introducing the variables seems to confuse the regexp - although I'm
not sure. The documentation (perlre) doesn't seem to address this (or if
I've missed it, please point me to the relevant paragraph!), and my only
other source of "information" is Komodo's Rx Toolkit, which informs me
that it is attempting to match literal '{', literal 'descmin', literal
'descmax', and the dollars are 'end of string'.

Can I not use variables to describe the min and max in a match count
clause?
Jul 19 '05 #1
1 2425
David Frauzel <net.weathersongATnemo> wrote:
The documentation (perlre) doesn't seem to address this (or if I've
missed it, please point me to the relevant paragraph!), and my only
other source of "information" is Komodo's Rx Toolkit, which informs me
that it is attempting to match literal '{', literal 'descmin', literal
'descmax', and the dollars are 'end of string'.

Can I not use variables to describe the min and max in a match count
clause?


Sure you can. Maybe Komodo is interfering somehow...

$ perl -le '($x,$y) = (1,2); print for "foo" =~ /.{$x,$y}/g'
fo
o

The docs for this (in perlop: the "Gory details of parsing quoted
constructs") confirm that variable interpolation comes before the
compilation of the regex.

--
Steve
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Lasher | last post by:
Hello, I would like to create a set of very similar regular expression. In my initial thought, I'd hoped to create a regular expression with a variable inside of it that I could simply pass a...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
1
by: Al Jones | last post by:
This was originally posted in the VBScript forum, several of my other questions have been vbscript related, one of the fine fellows there suggest I might want to post it as well in the jscript...
2
by: bissatch | last post by:
I am trying to compare two variable but using regular expression: $access = "glasgow" $areaid = "glasgow-westend-byers_rd" using the two variables, I would like the areaid variable to be...
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...
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...
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...
2
by: Kai Rosenthal | last post by:
Hello, how can I resolve envionment variables in a string. e.g. strVar = /myVar resolve in str1 = /mytest02/$MYVAR/mytest02 --/mytest02//myVar/mytest02 (unix) str2 =$MYVAR/mytest03 ...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.