2012-04-24 12 views
0

この文字列を解析し、太字を抽出する必要があります。 Iは = "0067711990999999 * * 0515070999999999999N9 + 01 * * 1 + 99999999 ..." とすることができる 1 useInputに適した正規表現を持っていけません。文字列内の太字を認識するためのパターンマッチング

Pattern pattern; 
    String regex="\\s*-?\\d+(?:\\s*[-+/*]\\s*-?\\d+)+\\s*"; 
    pattern=Pattern.compile(regex); 
    Matcher match = pattern.matcher(userInput); 

問題は、私は大胆な文字列にマッチする任意の正規表現を見つけるいけないです。

私はMap-Reduceプログラムでこれが必要です。

おかげ

+0

この文脈では、「太字」の数字は何ですか? – claesv

+0

上記のように** 1955年と温度* 23 *。 –

+1

フォントの変更自体は文字ではありません。おそらく、生の形式でのあなたの入力は、フォントの変更を示すある種のシーケンスを持っています。そのシーケンスとそれに一致すると判断することができます。このシーケンスがHTMLの場合、解析には非常に間違いがあります。 HTMLタグの一致に関する通常の問題とは別に、CSSについて心配する必要があるかもしれません。 – geekosaur

答えて

0

.odtファイルを読んでいる場合は、おそらくhttp://www.jopendocument.org/の方がいいですか?

+0

ok odtのために役立ちますが、.logファイルの場合は問題があります。しかし、とにかく感謝します。 –

0

次のコード

String myString = "0067711990999999*1955*0515070999999999999N9+01*23*1+99999999"; 
// matches all number series (one or more consecutive digits) 
// between * characters. * normally matches any character and 
// so has to be escaped using \, which in a string becomes \\, 
// i.e the regular expression is actually \*([0-9])\* 
Pattern pattern = Pattern.compile("\\*([0-9]+)\\*"); 
Matcher matcher = pattern.matcher(myString); 
while (matcher.find()) { 
    // the parantheses in the regex creates a capturing group, i.e. 
    // a substring within the match that can later be extracted. 
    // the "1" here means we're picking up the value of the first 
    // (and in this case, only) capturing group, which is the 
    // actual numbers (i.e. not including the * characters) 
    System.out.println(matcher.group(1)); 
} 

1955 
23 

を印刷し、あなたが探しているものということですか?

+0

はい。しかし、物事は入力* 1995 *と* 23 *太字の意味です。 *の文字列に含まれていないと私はログファイルと.odtファイルからこれらを読んでいる。 –

+0

[OK]を、私はここで正規表現があなたを助けることができると確信していません。上記の@geekosaurによるコメントを参照してください。質問を更新して、_actual_ userInput文字列をログファイル/ .odtファイルから読み込んでください。 – claesv

+0

ok。入力ログは006779195005150704 .................. 999999999999N9 + 00031 + 999999999 ....... 006771199991954051507004 .............. ···999999999999N9 + 00111 + 999999999 ....... 00677119909999991955051507004 .................. 999999999999N9....... 00677119909999991956051507004 .................. 999999999999N9 + 00121 + 999999999 ....... 00677119909999991957051507004 .................. 999999999999N9 + 00121 + 999999999 ....... 00677119909999995955199099991954051507004 .................. 999999999999N9 + 00511 + 999999999 ....... 00677119909999991954051507004 .... .............. 999999999999N9 + 00111 + 999999999 –

関連する問題