samjud
asked on
Java regex replace
i have a string in an xml file <Boxed_Length> </Boxed_Length> i need a regular expression in java to replace all spaces so instead it should say <Boxed_Length></Boxed_Leng th>
ASKER
i am running this in talend and got a invalid escape sequence error so i tried <Boxed_Length>\\s+</Boxed_ Lenth> it still does not work
ASKER
here is the full string i tried "<Boxed_Length>\\s+</Boxed _Length>&# (.*);"
Different tools and languages have different standards for regular expression syntax. The string you're using looks good for Java, but I don't know whether talend uses the same syntax; do you know?
It's worth noting, in case you didn't notice, that kaufmed's pattern was missing a letter g from the closing tag ie Boxed_Lenth should be Boxed_Length. It looks like you've fixed it in your latest pattern, but I'm pointing it out just in case it makes a difference.
It's worth noting, in case you didn't notice, that kaufmed's pattern was missing a letter g from the closing tag ie Boxed_Lenth should be Boxed_Length. It looks like you've fixed it in your latest pattern, but I'm pointing it out just in case it makes a difference.
ASKER
As far as i know talend uses regular java expression syntax and yes i did fix the spelling in my test.
If it's easy and quick to change the pattern and retest, a good technique is to start with a very simple pattern like "Boxed_Length" and build up the complexity once you have the simple one working.
Alternatively, you may like to provide a copy and paste of the data you're trying to match. There might be (I'm guessing almost certainly is) something in the data that causes it to not match. It might be something as simple as a space between the > and & characters.
Alternatively, you may like to provide a copy and paste of the data you're trying to match. There might be (I'm guessing almost certainly is) something in the data that causes it to not match. It might be something as simple as a space between the > and & characters.
ASKER
below is an example of 1 xml record..
<Row>
<Item_SKU>MANOWAR16</Item_ SKU>
<Promo_Title>12" Guitar Speakers</Promo_Title>
<QTY_on_hand>7</QTY_on_han d>
<COST>61</COST>
<UPC>876358001583</UPC>
<Weight>9.9</Weight>
<Brand>EMINENCE</Brand>
<MSRP>89.99</MSRP>
<UAP>89.99</UAP>
<TOPCATEGORY>DJ,HOME,STAGE ,PERSONAL, RECREATION ,SCHOOL,IN STRUMENTAL ,PORTABLE, CLUB</TOPC ATEGORY>
<Boxed_Length> </Boxed_Length>
<Boxed_Height />
<Boxed_Width> </Boxed_Width>
<CCREATEDATE>2011-11-29T12 :40:50.68< /CCREATEDA TE>
<DATEMODIFIED>2014-1-22</D ATEMODIFIE D>
<MFG_PROD_ID>MANOWAR16</MF G_PROD_ID>
<Image_x0020_URL>/images/X YZ123/MANO WAR16.jpg< /Image_x00 20_URL>
<CATEGORY>WOOFERS-GUITAR-1 2IN</CATEG ORY>
<MFGCOUNTRY>CHINA</MFGCOUN TRY>
<Long_Description>SPECIFIC ATION
Nominal Basket Diameter 12", 304.8mm
Nominal Impedance* 16 ohms
Power Rating
Watts 120W
Music Program
Resonance 102Hz
Usable Frequency Range 70Hz-5.5kHz
Sensitivity*** 101.6
Magnet Weight 38 oz.
Gap Height 0.312", 7.92mm
Voice Coil Diameter 1.75", 44.5mm
SOUND CLIPS
THIELE & SMALL PARAMETERS Clean Heavy OD
Resonant Frequency (fs) 102Hz
DC Resistance (Re) 13.1
Coil Inductance (Le) 0.74mH
Download PDF Spec Sheet
Mechanical Q (Qms) 12.39
Electromagnetic Q (Qes) 0.97
Total Q (Qts) 0.85
Compliance Equivalent Volume (Vas) 31.5 liters / 1.1 cu.ft.
Mechanical Compliance of Suspension (Cms) 0.08mm/N
BL Product (BL) 16.5 T-M
Diaphram Mass inc. Airload (Mms) 30 grams
Efficiency Bandwidth Product (EBP) 105
Maximum Linear Excursion (Xmax) 0.8mm
Surface Area of Cone (Sd) 519.5 cm2
Maximum Mechanical Limit (Xlim)
MOUNTING INFORMATION
Recommended Enclosure
Sealed Acceptable
Vented Acceptable
Overall Diameter 12.02", 305.3mm
Baffle Hole Diameter 10.97", 278.6mm
Front Sealing Gasket fitted as standard
Rear Sealing Gasket fitted as standard
Mounting Holes Diameter 0.25", 6.4mm
Mounting Holes B.C. D. 11.63", 295.4mm
Depth 5.2", 132mm
Net Weight 8.1 lbs., 3.7 kg
Shipping Weight 9.9 lbs., 4.5 kg
MATERIALS OF CONSTRUCTION
Coil Construction Copper voice coil
Coil Former Polyimide former
Magnet Composition Ferrite magnet
Core Details Non-vented core
Basket Materials Pressed steel basket
Cone Composition Paper Cone
Cone Edge Composition Paper cone edge
Dustcap Composition Zurette dust cap
</Long_Description>
</Row>
<Row>
<Item_SKU>MANOWAR16</Item_
<Promo_Title>12" Guitar Speakers</Promo_Title>
<QTY_on_hand>7</QTY_on_han
<COST>61</COST>
<UPC>876358001583</UPC>
<Weight>9.9</Weight>
<Brand>EMINENCE</Brand>
<MSRP>89.99</MSRP>
<UAP>89.99</UAP>
<TOPCATEGORY>DJ,HOME,STAGE
<Boxed_Length> </Boxed_Length>
<Boxed_Height />
<Boxed_Width> </Boxed_Width>
<CCREATEDATE>2011-11-29T12
<DATEMODIFIED>2014-1-22</D
<MFG_PROD_ID>MANOWAR16</MF
<Image_x0020_URL>/images/X
<CATEGORY>WOOFERS-GUITAR-1
<MFGCOUNTRY>CHINA</MFGCOUN
<Long_Description>SPECIFIC
Nominal Basket Diameter 12", 304.8mm
Nominal Impedance* 16 ohms
Power Rating
Watts 120W
Music Program
Resonance 102Hz
Usable Frequency Range 70Hz-5.5kHz
Sensitivity*** 101.6
Magnet Weight 38 oz.
Gap Height 0.312", 7.92mm
Voice Coil Diameter 1.75", 44.5mm
SOUND CLIPS
THIELE & SMALL PARAMETERS Clean Heavy OD
Resonant Frequency (fs) 102Hz
DC Resistance (Re) 13.1
Coil Inductance (Le) 0.74mH
Download PDF Spec Sheet
Mechanical Q (Qms) 12.39
Electromagnetic Q (Qes) 0.97
Total Q (Qts) 0.85
Compliance Equivalent Volume (Vas) 31.5 liters / 1.1 cu.ft.
Mechanical Compliance of Suspension (Cms) 0.08mm/N
BL Product (BL) 16.5 T-M
Diaphram Mass inc. Airload (Mms) 30 grams
Efficiency Bandwidth Product (EBP) 105
Maximum Linear Excursion (Xmax) 0.8mm
Surface Area of Cone (Sd) 519.5 cm2
Maximum Mechanical Limit (Xlim)
MOUNTING INFORMATION
Recommended Enclosure
Sealed Acceptable
Vented Acceptable
Overall Diameter 12.02", 305.3mm
Baffle Hole Diameter 10.97", 278.6mm
Front Sealing Gasket fitted as standard
Rear Sealing Gasket fitted as standard
Mounting Holes Diameter 0.25", 6.4mm
Mounting Holes B.C. D. 11.63", 295.4mm
Depth 5.2", 132mm
Net Weight 8.1 lbs., 3.7 kg
Shipping Weight 9.9 lbs., 4.5 kg
MATERIALS OF CONSTRUCTION
Coil Construction Copper voice coil
Coil Former Polyimide former
Magnet Composition Ferrite magnet
Core Details Non-vented core
Basket Materials Pressed steel basket
Cone Composition Paper Cone
Cone Edge Composition Paper cone edge
Dustcap Composition Zurette dust cap
</Long_Description>
</Row>
Some considerations:
a. is this actually a Java question?
b. why in fact are you concerned with that particular whitespace - it's not as if there's much of it ..?
a. is this actually a Java question?
b. why in fact are you concerned with that particular whitespace - it's not as if there's much of it ..?
ASKER
a. i think so
b. it looks like talend has a feature (bug) so that when there is a record in an xml file that just has whitespace without any data it breaks and does not continue.. hence the need to remove the whitespace.
b. it looks like talend has a feature (bug) so that when there is a record in an xml file that just has whitespace without any data it breaks and does not continue.. hence the need to remove the whitespace.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
b. it looks like talend has a feature (bug) so that when there is a record in an xml file that just has whitespace without any data it breaks and does not continue.. hence the need to remove the whitespace.Then that's your real problem. Needless to say, it shouldn't be necessary to be finding workarounds like this for such a major platform
Open in new window