473,324 Members | 2,254 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,324 software developers and data experts.

search and replace using reg expression

I would like to search and replace an xml file with the ini content, but i am getting incorrect answer in my bb.xml with the same regular expression syntax without replacement.

My ini file
-----------
myPara para
lPara last_para
<mySeca>([0-9]+). <sec id=\"$1\">

My XML file.
-----------
Expand|Select|Wrap|Line Numbers
  1. <myPara>dsa fhasdjkh fjaksdhkjfh asjkdhfjk lashdkjfh ajksdhf jkasdhfjka sd</myPara>
  2. <lPara>asdfh asgdhfgsdf asdhf asdhgf asd</lPara>
  3. <mySeca>1. asdfgashdgfhasdghfg sdhfg asd</mySeca>
my perl part
--------------
Expand|Select|Wrap|Line Numbers
  1. $filename = "c:\\temp\\temp\\F&R.ini";
  2. my $raw="c:\\temp\\temp\\aa.xml";
  3. my $output="c:\\temp\\temp\\bb.xml";
  4. open ($FIN,$raw) or die "Could not read from $raw, program halting.";
  5. my $instr;
  6. while (my $lines=<$FIN>)
  7. {
  8.     $instr.=$lines."";
  9. }
  10. open(FILE, $filename) or die "Could not read from $filename, program halting.";
  11. $count = 1;
  12. while (<FILE>)
  13. {
  14. chomp($_);
  15. my($find,$replace)=split(/\t/,$_,2);
  16. $instr=~s/$find/sub{$replace}->()/gei;
  17. count++;
  18. }
  19. open(FOUT,">$output"); print FOUT $instr; close FOUT;
  20.  
output bb.xml
------------
Expand|Select|Wrap|Line Numbers
  1. <para>dsa fhasdjkh fjaksdhkjfh asjkdhfjk lashdkjfh ajksdhf jkasdhfjka sd</para>
  2. <last_para>asdfh asgdhfgsdf asdhf asdhgf asd</last_para>
  3. <sec id=\"$1\">asdfgashdgfhasdghfg sdhfg asd</mySeca>
Can anyone help me to solve this
Apr 26 '12 #1
0 1196

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

Similar topics

0
by: Kostya Altuhov | last post by:
It is really a pain to use a completely different syntax each time I want to do a search or replace using regular expressions in VS IDE. Why don't you support the normal regex syntax, i.e. the...
5
by: Ones Self | last post by:
Hi all: I'm trying to replace using a regexp read from a file: $string = '123 456 789'; # these two are usualy read from a file, # and so have to be in variables. $re = '()'; $rep = '|$1|';
4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
0
by: DaveJG | last post by:
I have a couple of questions involving the search/replace in the IDE and regular expressions. Any help would be greatly appreciated. 1. How would I replace two line feeds with one? That is ...
2
by: Michael Peters | last post by:
is there a way to replace a certain sequence of characters by line feed (vbCrLf ), for all text columns in a table, using Search+Replace? -Michael
1
by: Casey | last post by:
Hi, How would one allow for possible multiple search criteria using FREETEXTTABLE. For example, my table "listings" has a full-text search catalog, and I may want to: SELECT * FROM listings...
4
by: ramkumar1910 | last post by:
Experts, I am trying to do serch and replace using regex, my problem is the search is a chunk of html enclosed in a div tag. and the contents are dynamic. Ex-- <div> <table></table> </div> ...
15
by: ritesh | last post by:
Hi, I'm working on a piece of code that - 1. has a list of text files 2. and needs to search for a particular expression in these files (this is being done on Linux using gcc 3.4.2) ...
1
by: pcplayer | last post by:
I am trying to create a regular expression that will search a memo and replace all values that are between "" brackets. Example: static void Main() { string text = @"This...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: 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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.