473,804 Members | 3,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

boost regex format string

Aek
Hi everyone,

I am trying to construct a regular expression and format string to use
with a boost::regex_re place()
In my file the sample text is:

// .fx shader file
FLOAT JOE 3545f;
FLOAT BLOGS -3343f;
FLOAT AMBIENT 2300.0f;
I have the regex to extract the top two incorrect float specifiers
(\s(|-)\d+f;) or the boost equivalent is regex string is
"([[:space:]](|-)[[:digit:]]+f;)"
which returns 3545f; and -3343f;

Now I am a bit confused by how I need to apply the format string to
take these two values and then insert ".0" between the last digit and
the "f;"

What sort of format string would I need for that?
Or am I going about the regex incorrectly to begin with?

Any help is appreciated,
Josh

Oct 26 '06 #1
7 4839
Aek

Aek wrote:
>
I have the regex to extract the top two incorrect float specifiers
(\s(|-)\d+f;)
I think I have a solution.
I changed the regex to include additional bracket for lexical grouping.
This means that the regex still only returns 2 results for the sample
text I posted earlier, but allows me to deal with each block of text
separately.

regex = (\s(|-)\d+)(f;)
now I can have a format string as
"\\1\\2" to print both the "3000" and "f;"
or
to solve my problem I set the format string to
"\\1.0f;" essentially discarding the \\2 and replacing it with a ".0f;"

Oct 26 '06 #2
Aek wrote:
Aek wrote:
>I have the regex to extract the top two incorrect float specifiers
(\s(|-)\d+f;)

I think I have a solution.
I changed the regex to include additional bracket for lexical grouping.
This means that the regex still only returns 2 results for the sample
text I posted earlier, but allows me to deal with each block of text
separately.

regex = (\s(|-)\d+)(f;)
now I can have a format string as
"\\1\\2" to print both the "3000" and "f;"
or
to solve my problem I set the format string to
"\\1.0f;" essentially discarding the \\2 and replacing it with a ".0f;"
That looks right, with the minor nit that it's the third submatch that's
being discarded, not the second.

On the other hand, if you're just going to throw away the third
submatch, you don't need to save it. So you can get rid of the
parentheses around f;.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 26 '06 #3
Aek
thanks for your suggestion.
I have removed the parentheses from around the f;

However I seem to be getting an Empty expression exception when
assigning my expression to my boost:regex object.

boost::regex exp;
const char* expression_stri ng = "([[:space:]](|-)[[:digit:]]+)f;";
exp.assign(expr ession_string);

Adding some additonal parentheses around the whole expression doesnt
seem to change the behaviour either.

Any ideas?
Pete Becker wrote:
Aek wrote:
Aek wrote:
I have the regex to extract the top two incorrect float specifiers
(\s(|-)\d+f;)
I think I have a solution.
I changed the regex to include additional bracket for lexical grouping.
This means that the regex still only returns 2 results for the sample
text I posted earlier, but allows me to deal with each block of text
separately.

regex = (\s(|-)\d+)(f;)
now I can have a format string as
"\\1\\2" to print both the "3000" and "f;"
or
to solve my problem I set the format string to
"\\1.0f;" essentially discarding the \\2 and replacing it with a ".0f;"

That looks right, with the minor nit that it's the third submatch that's
being discarded, not the second.

On the other hand, if you're just going to throw away the third
submatch, you don't need to save it. So you can get rid of the
parentheses around f;.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 27 '06 #4
Aek
Some more info
I am linking against the static libs
Using MS VS.net 2003 and boost 1.33.1

Oct 27 '06 #5
Aek
I managed to resolve this.For future reference...
Had to change the alternation operator in the middle from

(|-)
to
(?:)|-

as (?:) is used to represent an empty space

Oct 27 '06 #6
Aek wrote:
>
However I seem to be getting an Empty expression exception when
assigning my expression to my boost:regex object.

boost::regex exp;
const char* expression_stri ng = "([[:space:]](|-)[[:digit:]]+)f;";
exp.assign(expr ession_string);
I was surprised to see that (|-) seems to be a valid expression
according to the ECMAScript grammar. But my guess is that that's where
the problem is coming from, since the left side of that alternation is
the only empty subexpression. The more idiomatic way to say that is (-?).

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 27 '06 #7
Aek wrote:
I managed to resolve this.For future reference...
Had to change the alternation operator in the middle from

(|-)
to
(?:)|-

as (?:) is used to represent an empty space
(-?) is clearer.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 27 '06 #8

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

Similar topics

2
3710
by: Richard Latter | last post by:
Hello All, I am a newbie to the Boost library and I have a question about a simple function. All I would like to do is to create a simple function that can test strings using regular expressions. I've written this function which appears to work on the first pass and then fails on the second with the following message. Unhandle exeption in Credit Card Example.exe (KERNEL32.DLL) 0x(Some address): Microsoft C++ Exception.
5
7193
by: FBergemann | last post by:
I use SunOS 5.8, gcc 3.3.2, boost 1.33.1. I have build the entire boost package and try to compile a simple example: #include <iostream> #include <string> #include <boost/regex.hpp // Boost.Regex lib using namespace std;
3
2812
by: MCH | last post by:
hi there, I am working with a HTML-like text with boost:regex. For example, the following pattern might occur in my text <abc efg> <p>EFG</p 12<3> In this case, I would like to extract everything between and replace with <pre>, with </pre>. Meanwhile, everything outside should be unchaged except that < is
1
2155
by: Alan Patterson | last post by:
I have installed boost 1.33.1 and everything compiled and installed fine on Windows using Visual C++ 8.0. I wrote the following simple code to test the regex library and it doesn't seem to work. In the following "Matched" is not output to cout. Am I missing something or do I have a problem with my regex install? #include <string>
1
2861
by: Barry | last post by:
I used Boost.Xpressive after 1.3.4, and found it interesting and helpful, but I suffer from long complie-time. So I wonder there is a way to write the regular expression in Xpressive and use it in Boost.RegEx, since there grammer is simmilar to use
3
2618
by: neino | last post by:
Hello, did anyone of You have problems using boost::regex ? That code below : #include "boost/regex.hpp" /*1*/ int main() /*2*/ { /*3*/ boost::regex reg("*"); /*4*/
13
4536
by: brad | last post by:
Still learning C++. I'm writing some regex using boost. It works great. Only thing is... this code seems slow to me compared to equivelent Perl and Python. I'm sure I'm doing something incorrect. Any tips? #include <boost/regex.hpp> #include <iostream> // g++ numbers.cpp -o numbers -I/usr/local/include/boost-1_35 /usr/local/lib/libboost_regex-gcc41-mt-s.a // g++ numbers.cpp -o numbers.exe
2
3004
by: skip | last post by:
A colleague wrote a C++ library here at work which uses the Boost.regex library. I quickly discovered an apparent problem with how it searches. Unlike re.match the regex_match function in that library effectively anchors the match at both the start and the end. Can other people confirm this? Thx, Skip Montanaro
3
4542
by: rottmanj | last post by:
In my application I get a string from my datasource that I need to replace some of the bad chars in the strings. Right now I have written a pretty standard regex that should replace any of the bad chars in the strings. However, instead of removing the bad chars it removes all chars from the string. The bad chars I am trying to replace are /'() Here is the current code that I am testing with. boost::regex const...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4288
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 we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.