Java Regex接受任何东西而不是尖括号

时间:2016-01-21 06:47:51

标签: java regex

我希望在Java中使用正则表达式,它可以包含任何特殊字符,字母或数字,但不包含< > (尖括号)。

我找到了这个,import UIKit class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource{ @IBOutlet weak var tableView: UITableView! var rows: NSMutableArray! override func viewDidLoad() { super.viewDidLoad() self.rows = ["1","2","3","4","5","6","7"] self.tableView.reloadData() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func clearList(sender: AnyObject) { let alert = UIAlertController(title: "Clear List?", message: "Are you sure you want to clear the list?", preferredStyle: .Alert) let yesClearAction = UIAlertAction(title: "Yes", style: .Default, handler: { (action:UIAlertAction) -> Void in self.clearListNow("GroceryList") self.tableView.reloadData() }) let noClearAction = UIAlertAction(title: "No", style: .Default, handler: { (action:UIAlertAction) -> Void in //do nothing aka don't clear list }) alert.addAction(yesClearAction) alert.addAction(noClearAction) presentViewController(alert, animated: true, completion: nil) } func clearListNow(entity: String) { self.rows.removeAllObjects() } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ return self.rows.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ let cell = tableView.dequeueReusableCellWithIdentifier("FruitCell", forIndexPath: indexPath) as? MyCell cell!.textLabel?.text = self.rows[indexPath.row] as? String return cell! } } 但它给出了

  

转义序列无效

在我的代码中使用。

请帮忙。

1 个答案:

答案 0 :(得分:1)

 String regex="[^<>]*";
        Pattern p= Pattern.compile(regex);
        if(p.matcher("your input string").matches()){
            // place for your logic
        }